不让拖动的标题栏, 双击标题栏无反应
1
using System;
2
using System.Windows.Forms;
3
4
public class Test : Form
5
{
6
Test()
7
{
8
Text = "不让拖动的标题栏, 双击标题栏无反应";
9
FormBorderStyle = FormBorderStyle.FixedDialog;
10
MaximizeBox = false;
11
MinimizeBox = false;
12
}
13
14
protected override void WndProc(ref Message m)
15
{
16
base.WndProc(ref m);
17
if(m.Msg == 0x84 && m.Result == (IntPtr)2) // 不让拖动标题栏
18
{
19
m.Result = (IntPtr)1;
20
}
21
if (m.Msg == 0xA3) // 双击标题栏无反应
22
{
23
m.WParam = System.IntPtr.Zero;
24
}
25
}
26
27
static void Main()
28
{
29
Application.Run(new Test());
30
}
31
}
从CSDN论坛上看来的,遗憾的是还可以在标题栏上点右键来移动窗口,应该也是可以禁止的,但我对WndProc不熟悉,不知道该怎么实现。
using System;2
using System.Windows.Forms;3

4
public class Test : Form5
{6
Test()7
{8
Text = "不让拖动的标题栏, 双击标题栏无反应";9
FormBorderStyle = FormBorderStyle.FixedDialog;10
MaximizeBox = false;11
MinimizeBox = false;12
}13

14
protected override void WndProc(ref Message m)15
{16
base.WndProc(ref m);17
if(m.Msg == 0x84 && m.Result == (IntPtr)2) // 不让拖动标题栏18
{19
m.Result = (IntPtr)1;20
}21
if (m.Msg == 0xA3) // 双击标题栏无反应22
{23
m.WParam = System.IntPtr.Zero;24
}25
}26

27
static void Main()28
{29
Application.Run(new Test());30
}31
}


浙公网安备 33010602011771号