Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无标题的可移动表格_C#_Forms_Class - Fatal编程技术网

C# 无标题的可移动表格

C# 无标题的可移动表格,c#,forms,class,C#,Forms,Class,早些时候,我在这个论坛上寻找帮助来解决这个问题。基本上,我是从一个类中动态创建一个表单,我希望它可以在屏幕上拖动,而不需要标题栏。我遇到的代码是: public const int WM_NCLBUTTONDOWN = 0xA1; public const int HT_CAPTION = 0x2; [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern int SendMessage(IntPt

早些时候,我在这个论坛上寻找帮助来解决这个问题。基本上,我是从一个类中动态创建一个表单,我希望它可以在屏幕上拖动,而不需要标题栏。我遇到的代码是:

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

private void window_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        ReleaseCapture();
        SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
    }
}
但是,当我尝试编译时,会出现以下错误:

错误1当前数据库中不存在名称“句柄” 上下文C:\Users\xxxxxx\Documents\visualstudio 2013\Projects\practiceProgressBar2\practiceProgressBar2\Notifications.cs 109 29 practiceProgressBar2

有人知道我做错了什么吗,因为我整天都在解决这个问题。改变:

SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
致:

如果有其他控件(如标签)指向同一处理程序,则可以使用此控件在拖动标签时使其拖动:

SendMessage(((Control)sender).FindForm().Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);

请尝试替代表单的
WndProc
方法

public const int HTCAPTION = 0x2;
public const int WM_NCHITTEST = 0x84;
public const int HTCLIENT = 1;

protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);

    if (m.Msg == WM_NCHITTEST)
    {
        if (m.Result.ToInt32() == HTCLIENT)
            m.Result = (IntPtr)HTCAPTION;
    }
}

看起来你不是在表单中使用这些代码,你能发布更多的类吗?它是否继承自
表单
?public void startMessageIndicator(字符串消息){window.Size=new System.Drawing.Size(360150);window.FormBorderStyle=System.Windows.Forms.FormBorderStyle.None;window.TransparencyKey=System.Drawing.Color.Turquoise;window.BackColor=System.Drawing.Color.Turquoise;字符串消息=Interaction.InputBox(“问题?”,“标题”,“默认文本”);messageindicator.startMessageIndicator(message);我已经显示了一些类代码以及调用类的主代码谢谢,只需将单词Form替换为我希望启用此功能的窗口的名称即可?您只需将其保留为泛型
表单
类型,无需强制转换为特定类型。
public const int HTCAPTION = 0x2;
public const int WM_NCHITTEST = 0x84;
public const int HTCLIENT = 1;

protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);

    if (m.Msg == WM_NCHITTEST)
    {
        if (m.Result.ToInt32() == HTCLIENT)
            m.Result = (IntPtr)HTCAPTION;
    }
}