110,538
社区成员
发帖
与我相关
我的任务
分享
public Form1()
{
InitializeComponent();
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof (Button)))
e.Effect = DragDropEffects.Copy;
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
Button btn = new Button();
btn.Size = button1.Size;
btn.Location = this.PointToClient(new Point(e.X, e.Y));
this.Controls.Add(btn);
btn.Text = "按钮";
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
button1.DoDragDrop(button1, DragDropEffects.Copy | DragDropEffects.Move);
}
e.Effect = DragDropEffects.Copy
这句话,我发现任何鼠标拖拽都没有起作用。添加按钮的代码是在Form1_DrapDrop里面实现的,为何不设置鼠标样式,连功能都会出不来呢?