I'm trying to display one form relative to a Button on a control below it.
But Button.top is relative to the titlebar of the bottom form, and the top form will be relative to the screen.
So, to compensate for that I need to now how tall the titlebar is.
I've used Form.height-Form.ScalehHeight but ScaleHeight doesn't include the title bar or the border so Scaleheight is inflated slightly.
Anyone know how to calculate the height of just the title bar?
You need to use the GetSystemMetrics
API call to get the height of the titlebar.
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CYCAPTION = 4
Property Get TitleBarHeight() as Long
TitleBarHeight = GetSystemMetrics(SM_CYCAPTION)
End Property
Note: This will return the height in pixels. If you need twips you will have to convert using a form's ScaleY
method like so: Me.ScaleY(TitleBarHeight(), vbPixels, vbTwips)
Subtract it back out:
(Form.height-Form.ScaleHeight) - (Form.Width-Form.ScaleWidth) / 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With