R – Vista and Windows 7 borders cut off form content

borderformswindows 7windows-vista

Forms on Windows 7 and Vista have thicker borders than those of XP. As a result, some content that spans the entire height or width of a form will be cut off. Is there a simple way to fix this, or do all the forms of my application need to be resized to accommodate for this?

Update: It appears to be the fault of the form size and not the borders that are causing the problem. See the following images for an example. Notice how the controls have the correct location at the top-right corners, but they reach the each of the form in Windows 7 while a border is retained in XP. The same code is used to resize and position the controls.

Here's what a form looks like in XP:
alt text http://img504.yfrog.com/img504/1328/bordersxp.png

Best Answer

You should fix the size of the form programatically, to make sure the client size is big enough to fit everything. You can easily calculate the difference between the current size and client size of the form, and increase/decrease by the right amount.

You probably want to perform this inside Form_Load.

In VB6, the client size and width are referred to as ScaleWidth and ScaleHeight for forms. Setting these values just messes up the scaling, rather than resizing the form, so you instead have to do calculations so you can set the normal Width and Height properties.

BorderSize = Me.Width - Me.ScaleWidth
Me.Width = BorderSize + CorrectScaleWidth
//Same for height!
Related Topic