If you adjust your controls using ScaleWidth and ScaleHeight, the size of
the borders won't matter. ScaleWidth/ScaleHeight are based on the client
area of the form (the inside minus the borders, titlebar, etc.). If you want
to find out when the border changes, just check for a change in
ScaleWidth/ScaleHeight in the Paint event. Whenever a system property
changes that would affect the size, style, color, etc of your form, Windows
will send a WM_PAINT event to update the form.
Example:
Private Sub Form_Paint()
Static fScaleWidth As Single
Static fScaleHeight As Single
If Me.ScaleWidth <> fScaleWidth Or _
Me.ScaleHeight <> fScaleHeight Then
fScaleWidth = Me.ScaleWidth
fScaleHeight = Me.ScaleHeight
'Note: Your resize function should be based
'on the ScaleWidth/ScaleHeight of the Form,
'instead of the Width/Height.
Call ResizeControls
End If
End Sub
Note: If your Form.AutoRedraw = True then you will need to find another way
(subclassing or maybe a timer(yuk) control), since the Paint event will not
fire while AutoRedraw is on.
If you still need the border width/height, the following code will return
them in twips:
BorderWidth = Me.Width - _
Me.ScaleX(Me.ScaleWidth, Me.ScaleMode, vbTwips)
BorderHeight = Me.Height - _
Me.ScaleY(Me.ScaleHeight, Me.ScaleMode, vbTwips)
The Titlebar height can be calculated as follows:
TitlebarHeight = BorderHeight - BorderWidth
Note: There are API functions to return these figures, but this is just as
easy and you won't need any API declares.
Hope this helps,
Rocky
Quote:> Hi,
> I need to find out the size of the borders on a form. If someone
> changes their display settings from small fonts to big fonts the
> thickness changes in the borders around the form and I have to detect
> this in my app to make some adjustments of some controls. While we are
> here, is there also a way to get the height and width of the title bar?
> Thanks for your time,
> Guy