跨 MDI 子窗体的拖放操作
我正在尝试执行一个简单的拖放操作,从一个 MDI 子窗体中的一个按钮开始到另一个 MDI 子窗体中的另一个按钮。然而,由于某种原因,当我尝试将一个按钮拖动到另一个按钮时,DragDrop 事件永远不会被触发。值得注意的是,当我拖动按钮时,我的光标变成黑色取消图标。
我的代码:
#region ActivatesDragDropControl
[DllImport ("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
private const int WM_NCACTIVATE = 0x0086;
#endregion
private void button1_MouseDown(object sender, MouseEventArgs e)
{
DoDragDrop(LocationNode, DragDropEffects.Link);
// to deactivate
SendMessage(Handle, WM_NCACTIVATE, 0, 0);
}
private void button1_DragDrop(object sender, DragEventArgs e)
{
//never gets here...
}
private void button1_DragEnter(object sender, DragEventArgs e)
{
// to activate
SendMessage(Handle, WM_NCACTIVATE, 1, 0);
}
I am trying to perform a simple drag-n-drop operation starting from one button in one MDI child form to another button in a different MDI child form. For some reason however the DragDrop event never gets fired when I attempt to drag one button to the other. It may be worth noting that when I drag the button my cursor becomes the black-cancel icon.
My code:
#region ActivatesDragDropControl
[DllImport ("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
private const int WM_NCACTIVATE = 0x0086;
#endregion
private void button1_MouseDown(object sender, MouseEventArgs e)
{
DoDragDrop(LocationNode, DragDropEffects.Link);
// to deactivate
SendMessage(Handle, WM_NCACTIVATE, 0, 0);
}
private void button1_DragDrop(object sender, DragEventArgs e)
{
//never gets here...
}
private void button1_DragEnter(object sender, DragEventArgs e)
{
// to activate
SendMessage(Handle, WM_NCACTIVATE, 1, 0);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我又玩了一下,使用 DragEnter 还不够;我必须设置 DragEventArgs 的事件值。就我而言:
OK so I played around a bit more and using DragEnter isn't enough; I had to set the DragEventArgs' Event value. In my case: