Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get height of forms border in pixels

Status
Not open for further replies.

DevonTaig

Programmer
Joined
May 2, 2001
Messages
73
Location
US
I am wondering what is the best way to get the height of a forms border (the area at the top of the form that usually has minimize / maximize buttons) in pixels?

In the code below, the width of the border is found, but it is obviously NOT a very good solution.

Private Sub Command1_Click()
'Get the width of the forms border
Form1.WindowState = vbMaximized
Dim BorderWidth As Long
BorderWidth = (Screen.Height - Form1.Height)
Form1.WindowState = vbNormal
MsgBox BorderWidth
End Sub
 
Try using the form scale properties.

borderwidth=(me.width - me.scalewidth)/2

I used the width because I believe the height includes the title bar. Thanks and Good Luck!

zemp
 
You can read the value from the registy. It is in the HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\CaptionHeight Key. You will need to divide the value by 15 to get the height in pixels. If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]

[cheers]
 
Ratio of Twips per Pixel will vary depending on screen resolution, hardware and the whether you are referring to screen or printer. It can also be different in X and Y directions.

It can be obtained with the standard VB functions:
Screen.TwipsPerPixelX
Screen.TwipsPerPixelY
Printer.TwipsPerPixelX
Printer.TwipsPerPixelX Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Here is what I use. Do not try to use the LOGFONT data or anything following because they are variable length fields. They are set to max in the structure so there will be enough memory.
Private m_NonClientMetrics As NONCLIENTMETRICS
Private Type LOGFONT
lf1(3) As Byte
lf2(3) As Byte
lf3(3) As Byte
lf4(3) As Byte
lf5(3) As Byte
lf6 As Byte
lf7 As Byte
lf8 As Byte
lf9 As Byte
lf10 As Byte
lf11 As Byte
lf12 As Byte
lf13 As Byte
lf14(31) As Byte
End Type
Private Type NONCLIENTMETRICS
cbSize As Long
iBorderWidth As Long
iScrollWidth As Long
iScrollHeight As Long
iCaptionWidth As Long
iCaptionHeight As Long
lS5 As LOGFONT
iS6 As Long
iS7 As Long
lS8 As LOGFONT
iMenuWidth As Long
iMenuHeight As Long
lS11 As LOGFONT
lS12 As LOGFONT
lS13 As LOGFONT
lLONGZero As Long
End Type

Private Function VBSystemParametersInfoNonClientMetrics() As Long
Const SPI_GETNONCLIENTMETRICS = 41
m_NonClientMetrics.cbSize = 340
VBSystemParametersInfoNonClientMetrics = _
SystemParametersInfoNonClientMetrics(SPI_GETNONCLIENTMETRICS, _
0, _
m_NonClientMetrics, _
0)

End Function Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top