Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I've done the following (on a button click):

C++
int width = Form1::Width::get();
int height = Form1::Height::get();

this->textBox1->Text = Convert::ToString( width );
this->textBox2->Text = Convert::ToString ( height );


My screen resolution is 1440 by 900, but the textboxes give it as 1446 x 876.

I was just curious why this is?
Posted

The whole approach of using absolute sizes and positions in the form/window design is wrong. You can easily develop a fluid design to make it tolerant to screen size. I explained it in my past answers:
Zom Out malfunctions when Screen resolution changes[^],
how to dock button so that it can adjust with the form[^].

[EDIT]

The explanation of maximization give in Solution 2 is correct, but you also should take into account that the window is maximized in the area free from the system tray. See also my comments to Solution 2.

—SA
 
Share this answer
 
v2
Comments
nv3 25-Mar-13 3:43am    
Sergey, that was not his question.
Sergey Alexandrovich Kryukov 25-Mar-13 11:18am    
Well, I think it is related. The "essential" part of the question was unclear. What's "the textboxes give..."? how do you think?
The whole issue, if any, should be avoided rather than "resolved". Can you see my point?
—SA
nv3 25-Mar-13 11:27am    
What he meant is: He has a dialog and has maximized it. Then he retrieved the window size of that dialog and showed (as a debugging tool) the width and height values in two text boxes. The point is not how he is positioning the text boxes, but why the dialog size could be larger than his screen size. Due to the language barrier that was not all too obvious and I had to read the question a couple times until I understood his question.

Thanks for the 5!
Sergey Alexandrovich Kryukov 25-Mar-13 11:30am    
From your answer, I would assume that he first maximized the window and than read the actual size of it. I just explained what is not explained in your answer and what else should be taken into account. Agree?
—SA
nv3 25-Mar-13 11:35am    
Absolutely!
Yes, that is an interesting observation. You have probably maximized your Form1 before you took its size. Now, what Windows does when it maximizes a frame window is: It increases its size such that the window frame falls outside the screen area. Hence visually the frame disappears. Behind the scenes, however, the window starts at some negative position and is slightly larger than the screen. That explains your observation.

[EDIT] Answer to your additional question:

You can retrieve the size of the so-called workarea by calling SystemParametersInfo with argument SPI_GETWORKAREA. See SystemParametersInfo[^].
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 25-Mar-13 11:22am    
You explanation of how minimization works is quite correct, I know it for sure. (Well, actually, I voted 5, even though it does not answer the question.)

Now, it does not explain the OP's statement. Pay attention: OP states that the width is bigger then the screen width, but height is smaller than the screen height.

My explanation is: OP did also not take into account the height of system tray bar.

—SA
nv3 25-Mar-13 11:31am    
Oh, I missed that subtlety. And you are fully correct. It is the system task bar that reduces the dialog's usable area by some 30 pixels. Thanks for pointing that out, Sergey.
Sergey Alexandrovich Kryukov 25-Mar-13 12:52pm    
Sure.
—SA
lostandconfused1234 25-Mar-13 13:22pm    
Thanks for both your answers. My form automatically adjusts to the screen resolution of a computer. What is the simplest method to obtain the window size, excluding the task bar? Many thanks
nv3 25-Mar-13 13:39pm    
See the edit to my answer, above.
You should use the GetSystemMetrics function[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900