0

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.

officer
  • 2,080
  • 1
  • 20
  • 29
  • possible duplicate of [How do I make a WinForms app go Full Screen](http://stackoverflow.com/questions/505167/how-do-i-make-a-winforms-app-go-full-screen) –  Jul 04 '13 at 07:51
  • As i mentioned the title bar should be visible and it's the title bar which is causing the problems. – officer Jul 04 '13 at 07:56
  • @officer you want your form maximized but with `Maximize button` disabled? That's strange. is your form fixed in size? – King King Jul 04 '13 at 07:58
  • Yes, i want the form loaded maximized and stay that size, because i draw a chart on this form which takes a few seconds to render and everytime the window gets resized it does the rendering. I tried pretty much every `FormBorderStyle`, but it won't work... – officer Jul 04 '13 at 08:02

1 Answers1

1
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);            
  }
}
King King
  • 61,710
  • 16
  • 105
  • 130
  • That's exactly what I got, but if i drag or double-click the titlebar, the form still goes into windowed mode. – officer Jul 04 '13 at 08:09
  • @officer sorry, I didn't notice the detail of your words. I updated my answer with a working solution. – King King Jul 04 '13 at 08:35
  • Thank you, works almost fine now. The problem is that the form is behind the taskbar now, so I got some problems with my docked controls. To solve this I set the `MaximumSize` to a smaller height, but that's a bit dirty. Is there a better way to accomplish this? – officer Jul 04 '13 at 09:29
  • @officer I didnt notice that issue. I don't understand why it acts that way, but maybe the form is not loaded when `MaximizeBox = false;`, there is something wrong here. I updated with setting `MaximizeBox = false` when the form is loaded. Please see. – King King Jul 04 '13 at 09:39
  • Now it works perfectly fine - thank you for your time. Just for my understanding: `MaximizeBox = false;` gets executed after FormLoad is finished? I'm not very used to lambda expressions. – officer Jul 04 '13 at 09:54
  • @officer in fact the code I wrote above `MaximizeBox = false;` is placed in an Event Handler for the event `Load` of the `Form`. I love lamda expression in such a case when I don't have to think out a name for my Event handler :) – King King Jul 04 '13 at 10:20
  • Nice, learned something new - goal of the day accomplished. :) – officer Jul 04 '13 at 10:44