문제

I want to create a new form, which is set to maximized. It should show the title bar and the taskbar. This wasn't a big problem so far. When i set this.MaximizeBox = false; the button on the title bar gets disabled but if I drag or double click the title bar the form goes into window mode (tested on Windows 7).

Setting MinimumSize and MaximumSize to the same value wasn't successful.

도움이 되었습니까?

해결책

public class Form1 {
  public Form1(){
      InitializeComponent();
      WindowState = FormWindowState.Maximized;
      Load += (s,e) => {
         MaximizeBox = false;        
      };
  }
  bool hitControlButtons;
  protected override void WndProc(ref Message m)
  {
     if ((!hitControlButtons) && (m.Msg == 0xa3 || m.Msg == 0xa1))//WM_NCLBUTTONDBLCLK and WM_NCLBUTTONDOWN
     {                
        return;
     }
     if (m.Msg == 0xA0)//WM_NCMOUSEMOVE
     {
        int wp = m.WParam.ToInt32();                
        hitControlButtons = wp == 8 || wp == 20 || wp == 9;//Mouse over MinButton, CloseButton, MaxButton                               
     }
     base.WndProc(ref m);            
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top