跨 MDI 子窗体的拖放操作

发布于 2024-10-04 04:02:36 字数 867 浏览 0 评论 0原文

我正在尝试执行一个简单的拖放操作,从一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妞丶爷亲个 2024-10-11 04:02:36

好吧,我又玩了一下,使用 DragEnter 还不够;我必须设置 DragEventArgs 的事件值。就我而言:

e.Effect = DragDropEffects.Link;

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:

e.Effect = DragDropEffects.Link;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文