简体   繁体   English

C#在Form中移动Panel

[英]C# Move Panel inside Form

I would like to make certain panels within my Form draggable/movable. 我想在我的表格中制作某些可拖动/可移动的面板。 I have integrated: 我已整合:

    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();

as per other answers I have found here. 按照我在这里找到的其他答案。 Along with: 随着:

    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);
        }
    }

And what seems to happen is the whole Form moves instead of just the Panel(pnlSettings). 而似乎发生的是整个Form移动而不仅仅是Panel(pnlSettings)。 I can't seem to figure out how to get the panel alone to move. 我似乎无法弄清楚如何单独移动面板。

Handle is the handle of the form. Handle是表单的句柄。

You need to pass the .Handle of the control you want to move. 您需要传递要移动的控件的.Handle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM