Drag & Drop 기능 구현 기초

1. 드래그 해서 전달하려고 하는 클래스 선언

namespace DragTest
{
    public class Class1
    {
        public int a = 0;
    }
}

2. 드래그(Drag) 하려고 하는 항목에 MouseDown 이벤트를 생성하고 이벤트 내부에 드래그 시작을 알리는 함수 구현

using System;
using System.Windows.Form;

namespace DragTest
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_MouseDown(object sender, MouseEventArgs e)
        {
            this.DoDragDrop(new Class1(), DragDropEffects.Copy);
        }
    }
}

3. 드래그한 객체를 받아드릴 컨트롤 또는 폼에 AllowDrop 속성을 True로 설정

4. DragEnter 이벤트 구현

5. DragDrop 이벤트 구현



Leave a Reply