Solved

C# Windows Form odd behavior (maximize)

Posted on 2009-07-13
5
639 Views
Last Modified: 2013-12-17
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.

Thanks.

PS - I'm using VS 2008, and I know I'm not imagining things b/c I found this post describing the same thing:
http://bytes.com/groups/net/790544-vs2008-taskbar-hidden-when-windowstate-maximized-maximizebox-false
0
Comment
Question by:JCDBNRH
  • 2
5 Comments
 
LVL 1

Expert Comment

by:smousavi
ID: 24843626
try this :

this.WindowState = FormWindowState.Maximized;

this will maximize the form programatically , no need to have a maximize button
0
 

Author Comment

by:JCDBNRH
ID: 24843665
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.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 24844041
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);
        }

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24844051
*This also takes into account any other AppBar type applications that have properly registered themselves with the system.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question! 4 36
Printing 1 51
Hey!!!! 1 20
Database Connections Not being returned to Connection Pool 7 25
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question