-1

The following code does not show the Form's ClientSize when maximized:

WindowState = FormWindowState.Maximized;
Text = ClientSize.ToString();

How do I get that, so I can calculate Control sizes before the Form is maximized?

I rather not use hacks. I'm wondering if there is a simple way built in to Winforms. Relying on hacks like Screen WorkingArea and the like is prone to bugs. Consider, for example, what would happen if someone at some point changes the window to have a custom sized border. Will they remember/know that they have to fix this too?

ispiro
  • 26,556
  • 38
  • 136
  • 291
  • 1
    other references that you can checkout in regards to similar questions being asked here on SO http://stackoverflow.com/questions/254197/how-can-i-get-the-active-screen-dimensions – MethodMan Jan 19 '15 at 20:43
  • First, I'd want to know why you want to know. Are you trying to scale? Form controls should be laid out such that control location/sizing/etc. is handled by the form, and not by you in code. I.e. use a `TableLayoutPanel` or some such thing. – DonBoitnott Jan 19 '15 at 21:31
  • @DonBoitnott I wish it were always that simple... – ispiro Jan 19 '15 at 21:41
  • 1
    You cannot get an accurate size until the native window is created. You'll have to move that code into an event handler for the Load event. One of the few reasons to use it. – Hans Passant Jan 19 '15 at 22:02
  • @HansPassant Thanks. You can transform your comment into an answer so I can accept it. – ispiro Jan 19 '15 at 23:23

1 Answers1

0

You could use

Screen.FromControl(this).WorkingArea.Size
adv12
  • 8,443
  • 2
  • 24
  • 48
  • Thanks. I updated my question (presumably while you were writing your answer) to say I'm looking for a Winforms way of doing this = Getting it from winforms after it has "maximized" the Form (though not shown it). – ispiro Jan 19 '15 at 20:45