版权声明:欢迎转载,注明出处:来自CSDN博客作者弓人水。原文地址: https://blog.csdn.net/zzs0829/article/details/3750939
窗体禁止拖动标题栏和双击标题栏无效代码如下:
- using System;
- using System.Windows.Forms;
- namespace WindowsFormsTest1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- Text = "左键拖动标题栏无效, 双击标题栏无反应";
- FormBorderStyle = FormBorderStyle.FixedDialog;
- MaximizeBox = false;
- MinimizeBox = false;
- }
- protected override void WndProc(ref Message m)
- {
- base.WndProc(ref m);
- if (m.Msg == 0x84 && m.Result == (IntPtr)2) // 左键拖动标题栏无效
- {
- m.Result = (IntPtr)1;
- }
- if (m.Msg == 0xA3) // 双击标题栏无反应
- {
- m.WParam = System.IntPtr.Zero;
- }
- }
- static void Main()
- {
- Application.Run(new Form1());
- }
- }
- }
任何针对标题栏的操作都无效代码如下:
- protected override void WndProc(ref Message m)
- {
- if (m.Msg == 0xa1 && (int)m.WParam == 0x3)
- {
- return;
- }
- if (m.Msg == 0xa3 && ((int)m.WParam == 0x3 || (int)m.WParam == 0x2))
- {
- return;
- }
- if (m.Msg == 0xa4 && ((int)m.WParam == 0x2 || (int)m.WParam == 0x3))
- {
- return;
- }
- if (m.Msg == 0x112 && (int)m.WParam == 0xf100)
- {
- return;
- }
- base.WndProc(ref m);
- }