C# Windows Form odd behavior (maximize)

I have an app where I need to position some objects based on user-defined settings (I'm using the Properties.Settings), so I can't simply use align and dock methods.  The application runs maximized and I only want to have the cancel button shown.

I'm using the form.clientsize property to help with object positioning and have uncovered some odd behavior.  If I set WindowState = maximized, the value of this.ClientSize will vary depending on how I set MinimizeBox and MaximizeBox (true/false).  I've realized that it's because with the Min and Max boxes disabled, the form will run full-screen and extend itself underneath the taskbar.  Seems odd to me.

Any idea why this happens?  More importantly, can anyone tell me how to run the form so that it maximizes only to the visible area, yet with the Min and Max buttons hidden?  I know I could manually find the working area of the screen and subtract out the height of the taskbar, but wanted to see if there was a more direct and logical way.


PS - I'm using VS 2008, and I know I'm not imagining things b/c I found this post describing the same thing:
Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
You can get the "working area" DIRECTLY, thus removing any fudging/guesswork for the TaskBar size/position:

        private void Form1_Load(object sender, EventArgs e)
            Rectangle working = Screen.GetWorkingArea(this);
            this.SetBounds(working.X, working.Y, working.Width, working.Height);

try this :

this.WindowState = FormWindowState.Maximized;

this will maximize the form programatically , no need to have a maximize button
JCDBNRHAuthor Commented:
Please re-read my posting.  I don't want to have a maximize button.  I am maximizing the form in the code at run-time.  The problem is that with the Min and Max buttons set to false, the form size is not accurate.
Mike TomlinsonMiddle School Assistant TeacherCommented:
*This also takes into account any other AppBar type applications that have properly registered themselves with the system.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.