窗体标题栏操作控制

版权声明:欢迎转载,注明出处:来自CSDN博客作者弓人水。原文地址: https://blog.csdn.net/zzs0829/article/details/3750939

窗体禁止拖动标题栏和双击标题栏无效代码如下:

  1. using System;
  2. using System.Windows.Forms;
  3. namespace WindowsFormsTest1
  4. {
  5.     public partial class Form1 : Form
  6.     {
  7.         public Form1()
  8.         {
  9.             Text = "左键拖动标题栏无效, 双击标题栏无反应";
  10.             FormBorderStyle = FormBorderStyle.FixedDialog;
  11.             MaximizeBox = false;
  12.             MinimizeBox = false;
  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.         static void Main()
  27.         {
  28.             Application.Run(new Form1());
  29.         }
  30.     }
  31. }

任何针对标题栏的操作都无效代码如下:

  1.         protected override void WndProc(ref Message m)
  2.         {
  3.             if (m.Msg == 0xa1 && (int)m.WParam == 0x3)
  4.             {
  5.                 return;
  6.             }
  7.             if (m.Msg == 0xa3 && ((int)m.WParam == 0x3 || (int)m.WParam == 0x2))
  8.             {
  9.                 return;
  10.             }
  11.             if (m.Msg == 0xa4 && ((int)m.WParam == 0x2 || (int)m.WParam == 0x3))
  12.             {
  13.                 return;
  14.             }
  15.             if (m.Msg == 0x112 && (int)m.WParam == 0xf100)
  16.             {
  17.                 return;
  18.             }
  19.             base.WndProc(ref m);
  20.         } 

猜你喜欢

转载自blog.csdn.net/zzs0829/article/details/3750939