C#在Form中移动Panel

时间:2016-10-31 16:42:33

标签: c# drag-and-drop panel draggable movable

我想在我的表格中制作某些可拖动/可移动的面板。我已整合:

    public const int WM_NCLBUTTONDOWN = 0xA1;
    public const int HT_CAPTION = 0x2;
    [DllImportAttribute("user32.dll")]
    public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
    [DllImportAttribute("user32.dll")]
    public static extern bool ReleaseCapture();

根据我在这里找到的其他答案。以及:

    void pnlSettings_MouseMove(object sender, MouseEventArgs e)
    {
        Drag_Form(Handle, e);
    }
    public static void Drag_Form(IntPtr Handle, MouseEventArgs e){
        if (e.Button == MouseButtons.Left)
        {
          ReleaseCapture();
          SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
        }
    }

似乎发生的事情是整个Form移动而不仅仅是Panel(pnlSettings)。我似乎无法弄清楚如何单独移动面板。

1 个答案:

答案 0 :(得分:0)

Handle是表单的句柄。

您需要传递要移动的控件的.Handle

相关问题