1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DragAndDrop
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.AllowDrop = true;
this.MouseDown += new MouseEventHandler(dropSource_MouseDown);
this.DragEnter += new DragEventHandler(dropTarget_DragEnter);
this.DragDrop += new DragEventHandler(dropTarget_DragDrop);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void dropSource_MouseDown(object sender, MouseEventArgs e)
{
DoDragDrop(dropSource.Text, DragDropEffects.Copy);
}
private void dropTarget_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(string)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void dropTarget_DragDrop(object sender, DragEventArgs e)
{
dropTarget.Text = (string)e.Data.GetData(DataFormats.StringFormat);
}
}
}
|
cs |
'C#' 카테고리의 다른 글
c# winform timer (0) | 2021.11.07 |
---|---|
c# winform backgroundworker 스레드 중단/재개하기 코드 (1) | 2021.11.06 |
c# winform chart(only for .net framework) (0) | 2021.11.06 |
c# winform listview (0) | 2021.11.05 |
c# winform background worker 사용하기 (0) | 2021.11.05 |