0
내 목표는 텍스트를 한 버튼에서 다른 버튼으로 드래그하여 텍스트를 전환 할 수있는 여러 버튼을 갖는 것입니다. 버튼 자체를 전환 할 필요는 없으며 버튼 자체를 전환하는 것이 더 쉬운 경우에도 괜찮습니다.). 나는 this MSDN article을 따르려고했지만 실제로 드래그하기 시작하자마자 "아니오"기호가 표시됩니다. 내가 놓친 게 있니? (아래 코드)C#의 DragDrop 버튼 텍스트
미리 감사드립니다!
public partial class Form1 : Form
{
Button button1 = new Button();
Button button2 = new Button();
public Form1()
{
InitializeComponent();
button1.Text = "Button 1";
button2.Text = "Button 2";
button2.Location = new Point(100, 0);
this.Controls.Add(button1);
this.Controls.Add(button2);
button1.MouseDown += new MouseEventHandler(button_MouseDown);
button2.MouseDown += new MouseEventHandler(button_MouseDown);
button1.DragEnter += new DragEventHandler(button_DragEnter);
button2.DragEnter += new DragEventHandler(button_DragEnter);
button1.DragDrop += new DragEventHandler(button_DragDrop);
}
private void button_MouseDown(object sender, MouseEventArgs e)
{
((Button)sender).DoDragDrop(((Button)sender).Text, DragDropEffects.Move);
}
private void button_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void button_DragDrop(object sender, DragEventArgs e)
{
//I'm not sure what goes here, but I can figure that out through experimentation
}
}