C# WinForm:怎样使有标题栏的Form窗体不可移动?

只需要重写 WndProc方法

protected override void WndProc(ref Message m) 
{ 
   const int WM_NCLBUTTONDOWN = 161; 
   const int WM_SYSCOMMAND = 274; 
   const int HTCAPTION = 2; 
   const int SC_MOVE = 61456;
   if((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MOVE)) 
   { 
      return; 
   }
   if((m.Msg == WM_NCLBUTTONDOWN) && (m.WParam.ToInt32() == HTCAPTION)) 
   { 
      return; 
   }
   base.WndProc (ref m); 
}

 

posted @ 2013-02-18 10:12  乡香田甜  阅读(539)  评论(0编辑  收藏  举报