adjusting for differences in TitleBar and window border size in Win 7 with some Windows Effects turned on ?
-
The question: given the variety of visual effects in Vista and Win7 possibly applied to Windows Forms in .NET, depending on system settings, themes, etc., can you algorithmically determine the precise boundaries of the display area of a Form where 'display area' is defined as exclusive of window borders, titlebar height, side-effects of visual settings like 'shadows' on Forms, etc. And, oh yes, I don't wanna get near importing and using any API stuff ! :) Context: WinForm application, Visual Studio 2010 Pro, Win 7 Pro with all updates, 4 gigs of ram, older duo-core Intel CPU. GeForce 7100GS video card. Screen resolution: 1280x768 A concrete example: only W7 visual effects enabled: 1. desktop composition 2. use visual styles on buttons and windows In this software/hardware context: creating a "main" WinForm with a size set, in the design-time form editor, to, for example, 816,638, gets you this in the Designer.cs file:
this.ClientSize = new System.Drawing.Size(800, 600);
Now, I add a second Form at run-time to my WinForm app, and I set its owner to be the "main form." So: I write a re-size event-handler for this added, second, Form, so that I essentially keep it in the client display rectangle of the main Form: here's the way I (now) calculate the revised owner's client rectangle for "out of bounds detection:"
// defined in Form2 private Rectangle ownerClientRectangle; private Rectangle currentClientRectangle; private Rectangle intersectRectangle; // in the ReSize event for Form2 ownerClientRectangle = RectangleToScreen(RectangleToClient(this.Owner.Bounds)); ownerClientRectangle.Inflate(-14, -24); ownerClientRectangle.Offset(0, 12); currentClientRectangle = this.Bounds; intersectRectangle = currentClientRectangle; intersectRectangle.Intersect(ownerClientRectangle);
At this point I can be sure ... in this context only ... that if :
intersectRectangle != currentClientRectangle
Then the second Form is outside the boundaries of its owner ("main") Form, and I can 'do the right thing' to re-position it, which is simple. The problem here is those magic numbers I am using for shrinking (negatively inflating), and off-setting the owner form's Bounds. Of course I want to derive those inflation factors and offsets by calculation, not 'fiddlin around' :) If those W7 graphic effects are turned off: the ma
-
The question: given the variety of visual effects in Vista and Win7 possibly applied to Windows Forms in .NET, depending on system settings, themes, etc., can you algorithmically determine the precise boundaries of the display area of a Form where 'display area' is defined as exclusive of window borders, titlebar height, side-effects of visual settings like 'shadows' on Forms, etc. And, oh yes, I don't wanna get near importing and using any API stuff ! :) Context: WinForm application, Visual Studio 2010 Pro, Win 7 Pro with all updates, 4 gigs of ram, older duo-core Intel CPU. GeForce 7100GS video card. Screen resolution: 1280x768 A concrete example: only W7 visual effects enabled: 1. desktop composition 2. use visual styles on buttons and windows In this software/hardware context: creating a "main" WinForm with a size set, in the design-time form editor, to, for example, 816,638, gets you this in the Designer.cs file:
this.ClientSize = new System.Drawing.Size(800, 600);
Now, I add a second Form at run-time to my WinForm app, and I set its owner to be the "main form." So: I write a re-size event-handler for this added, second, Form, so that I essentially keep it in the client display rectangle of the main Form: here's the way I (now) calculate the revised owner's client rectangle for "out of bounds detection:"
// defined in Form2 private Rectangle ownerClientRectangle; private Rectangle currentClientRectangle; private Rectangle intersectRectangle; // in the ReSize event for Form2 ownerClientRectangle = RectangleToScreen(RectangleToClient(this.Owner.Bounds)); ownerClientRectangle.Inflate(-14, -24); ownerClientRectangle.Offset(0, 12); currentClientRectangle = this.Bounds; intersectRectangle = currentClientRectangle; intersectRectangle.Intersect(ownerClientRectangle);
At this point I can be sure ... in this context only ... that if :
intersectRectangle != currentClientRectangle
Then the second Form is outside the boundaries of its owner ("main") Form, and I can 'do the right thing' to re-position it, which is simple. The problem here is those magic numbers I am using for shrinking (negatively inflating), and off-setting the owner form's Bounds. Of course I want to derive those inflation factors and offsets by calculation, not 'fiddlin around' :) If those W7 graphic effects are turned off: the ma
I have had similar problems, the thing (from what I have gathered) is that when you set the
ClientSize
property the form resizes then changes theClientSize
again based on the theme settings (i.e. title bar header sizes). The outcome being your form keeps growing/shrinking (once) every time you show/hide. The best workaround I have found is to set the form size instead.Its the man, not the machine - Chuck Yeager If at first you don't succeed... get a better publicist If the final destination is death, then we should enjoy every second of the journey.
-
I have had similar problems, the thing (from what I have gathered) is that when you set the
ClientSize
property the form resizes then changes theClientSize
again based on the theme settings (i.e. title bar header sizes). The outcome being your form keeps growing/shrinking (once) every time you show/hide. The best workaround I have found is to set the form size instead.Its the man, not the machine - Chuck Yeager If at first you don't succeed... get a better publicist If the final destination is death, then we should enjoy every second of the journey.
Thanks for your response, Mehdi, In this case, I am using the "shrunken" bounding box of the client area of the Owner Form to hit test when a second, "owned" (but not child) Form is moved, and re-positioning the second Form to always remain in the boundaries of the first form. When I have time, I am going to experiment further with the differences between Form.Bounds, and the other Form-level 'area' properties under different conditions of configuring Win 7 visual effects, and see if I can't come up with some kind of compromise. best, Bill
"Is it a fact - or have I dreamt it - that, by means of electricity, the world of matter has become a great nerve, vibrating thousands of miles in a breathless point of time? Rather, the round globe is a vast head, a brain, instinct with intelligence!" - Nathanial Hawthorne, House of the Seven Gables
-
Thanks for your response, Mehdi, In this case, I am using the "shrunken" bounding box of the client area of the Owner Form to hit test when a second, "owned" (but not child) Form is moved, and re-positioning the second Form to always remain in the boundaries of the first form. When I have time, I am going to experiment further with the differences between Form.Bounds, and the other Form-level 'area' properties under different conditions of configuring Win 7 visual effects, and see if I can't come up with some kind of compromise. best, Bill
"Is it a fact - or have I dreamt it - that, by means of electricity, the world of matter has become a great nerve, vibrating thousands of miles in a breathless point of time? Rather, the round globe is a vast head, a brain, instinct with intelligence!" - Nathanial Hawthorne, House of the Seven Gables
Cheers Bill, I will try and investigate more (I gave up that feature last time!), let you know.
Its the man, not the machine - Chuck Yeager If at first you don't succeed... get a better publicist If the final destination is death, then we should enjoy every second of the journey.
-
The question: given the variety of visual effects in Vista and Win7 possibly applied to Windows Forms in .NET, depending on system settings, themes, etc., can you algorithmically determine the precise boundaries of the display area of a Form where 'display area' is defined as exclusive of window borders, titlebar height, side-effects of visual settings like 'shadows' on Forms, etc. And, oh yes, I don't wanna get near importing and using any API stuff ! :) Context: WinForm application, Visual Studio 2010 Pro, Win 7 Pro with all updates, 4 gigs of ram, older duo-core Intel CPU. GeForce 7100GS video card. Screen resolution: 1280x768 A concrete example: only W7 visual effects enabled: 1. desktop composition 2. use visual styles on buttons and windows In this software/hardware context: creating a "main" WinForm with a size set, in the design-time form editor, to, for example, 816,638, gets you this in the Designer.cs file:
this.ClientSize = new System.Drawing.Size(800, 600);
Now, I add a second Form at run-time to my WinForm app, and I set its owner to be the "main form." So: I write a re-size event-handler for this added, second, Form, so that I essentially keep it in the client display rectangle of the main Form: here's the way I (now) calculate the revised owner's client rectangle for "out of bounds detection:"
// defined in Form2 private Rectangle ownerClientRectangle; private Rectangle currentClientRectangle; private Rectangle intersectRectangle; // in the ReSize event for Form2 ownerClientRectangle = RectangleToScreen(RectangleToClient(this.Owner.Bounds)); ownerClientRectangle.Inflate(-14, -24); ownerClientRectangle.Offset(0, 12); currentClientRectangle = this.Bounds; intersectRectangle = currentClientRectangle; intersectRectangle.Intersect(ownerClientRectangle);
At this point I can be sure ... in this context only ... that if :
intersectRectangle != currentClientRectangle
Then the second Form is outside the boundaries of its owner ("main") Form, and I can 'do the right thing' to re-position it, which is simple. The problem here is those magic numbers I am using for shrinking (negatively inflating), and off-setting the owner form's Bounds. Of course I want to derive those inflation factors and offsets by calculation, not 'fiddlin around' :) If those W7 graphic effects are turned off: the ma
Hi Bill, I found the following link while answering a question in the quick answers CustomerBorderForm, it might help you out.
Its the man, not the machine - Chuck Yeager If at first you don't succeed... get a better publicist If the final destination is death, then we should enjoy every second of the journey.
-
Hi Bill, I found the following link while answering a question in the quick answers CustomerBorderForm, it might help you out.
Its the man, not the machine - Chuck Yeager If at first you don't succeed... get a better publicist If the final destination is death, then we should enjoy every second of the journey.
Thanks, Mehdi, I look forward to studying this; haven't found time yet to go back and start turning on and off Win 7 window styles and examining their various effects on DisplayRectangle, ClientRectangle, Bounds, etc. The last discussion forum item on that CodePlex project site[^] suggests to me there may be problems with that code on Win 7. But, I'll try it out, anyhow. best, Bill
"Is it a fact - or have I dreamt it - that, by means of electricity, the world of matter has become a great nerve, vibrating thousands of miles in a breathless point of time? Rather, the round globe is a vast head, a brain, instinct with intelligence!" - Nathanial Hawthorne, House of the Seven Gables