I need to determine if the Form has a titlebar or not. If it has a titlebar then how to check for the titlebar's height? Also, I need to check if the Form has borders and if it does the thickness of the borders.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: How to check if Form has a titlebar and borders
try like this to know the border widths
Code:
Private Sub FindBorderStyle(FormName As Form)
Dim FormBorderVertical As Single
Dim FormBorderHorizontal As Single
Dim FormBorderStyle As Single
FormBorderStyle = FormName.BorderStyle
FormBorderVertical = FormName.Width 'Keep first width
FormBorderHorizontal = FormName.Height 'Keep second width
FormName.BorderStyle = 0: FormName.Caption = FormName.Caption
FormBorderVertical = FormBorderVertical - FormName.Width 'First form width - Second form width
FormBorderHorizontal = FormBorderHorizontal - FormName.Height 'First form height - Second form height
FormName.BorderStyle = FormBorderStyle: FormName.Caption = FormName.Caption
MsgBox "BorderStyle: " & FormBorderStyle & vbNewLine & "Vertical Border Width: " & FormBorderVertical & vbNewLine & "Horizontal Border Width: " & FormBorderHorizontal
End Sub
Private Sub Command1_Click()
FindBorderStyle Me
End Sub
Re: How to check if Form has a titlebar and borders
Originally Posted by Max187Boucher
try like this to know the border widths
Code:
Private Sub FindBorderStyle(FormName As Form)
Dim FormBorderVertical As Single
Dim FormBorderHorizontal As Single
Dim FormBorderStyle As Single
FormBorderStyle = FormName.BorderStyle
FormBorderVertical = FormName.Width 'Keep first width
FormBorderHorizontal = FormName.Height 'Keep second width
FormName.BorderStyle = 0: FormName.Caption = FormName.Caption
FormBorderVertical = FormBorderVertical - FormName.Width 'First form width - Second form width
FormBorderHorizontal = FormBorderHorizontal - FormName.Height 'First form height - Second form height
FormName.BorderStyle = FormBorderStyle: FormName.Caption = FormName.Caption
MsgBox "BorderStyle: " & FormBorderStyle & vbNewLine & "Vertical Border Width: " & FormBorderVertical & vbNewLine & "Horizontal Border Width: " & FormBorderHorizontal
End Sub
Private Sub Command1_Click()
FindBorderStyle Me
End Sub
Max, it's not the width of the border I need; it's the thickness of the borders and the height of the titlebar. Also I don't understand what you say about
if horizontal border > 0 then has title bar and horizontal borders
if vertical border > 0 thn has vertical borders
It is not horizontal or vertical borders; it is always both horizontal and vertical or it's neither.
Last edited by jmsrickland; Aug 20th, 2012 at 03:03 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: How to check if Form has a titlebar and borders
again here
Code:
Private Sub FindBorderStyle(FormName As Form)
Dim FormBorderVertical As Single
Dim FormBorderHorizontal As Single
Dim FormBorderStyle As Single
FormBorderStyle = FormName.BorderStyle
FormBorderVertical = FormName.Width 'Keep first width
FormBorderHorizontal = FormName.Height 'Keep second width
FormName.BorderStyle = 0: FormName.Caption = FormName.Caption
FormBorderVertical = FormBorderVertical - FormName.Width 'First form width - Second form width
FormBorderHorizontal = FormBorderHorizontal - FormName.Height 'First form height - Second form height
FormName.BorderStyle = FormBorderStyle: FormName.Caption = FormName.Caption
MsgBox "BorderStyle: " & FormBorderStyle & vbNewLine & "Vertical Border Width: " & FormBorderVertical & vbNewLine & "Horizontal Border Width: " & FormBorderHorizontal
MsgBox "Title Bar HEIGHT (or thickness in you words): " & FormBorderHorizontal - (FormBorderVertical / 2)
MsgBox "Each Side EXCEPT title bars's THICKNESS is: " & (FormBorderVertical / 2)
End Sub
Private Sub Command1_Click()
FindBorderStyle Me
End Sub
Re: How to check if Form has a titlebar and borders
hopefully you understand this now... and when i said if horizontal border (FormBorderHorizontal) > 0 it means if its 0 then it has no borders or titlebar.
if it is more then 0 it means there is borders
sorry if you did not understand i thought i explained properly but i guess not
Edit: just for the record its in Twips and not Pixels or any other scalemode
Last edited by Max187Boucher; Aug 20th, 2012 at 02:55 PM.
Re: How to check if Form has a titlebar and borders
each border is 120 and the rest so if horizal total is 570 then top border is 120 and bottom is 120 what is the tittle bar (alone) height its 570 - 120 - 120 = 330 ... i wrote the top border with tittlebar height SORRY
Re: How to check if Form has a titlebar and borders
I'm not sure you understand. See attached image.
The border, if there is one is all around the Form so it's both horizontal and vertical. That's what confused me when you if vertical border > 0 then has vertical borders because it will always have vertical border if it has a horizontal border so why test for both?
You say it's in Twips but that has nothing to do with the thickness. The thickness is probably 2 but I do not know for sure and if all Border styles have the same thickness. The titlebar height is probably the same for all styles but what is it's height. That's what I asked for.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: How to check if Form has a titlebar and borders
OK, I can see about the thickness of the borders. They are 4-pixels. 4 * Screen.TwipsPerPixelX = 60 and that is what your message box says.
What confused me was your code says the titlebar's height is 345 which is the sum of the titlebar's height plus the top border thickness of 4 plus 1 which equals 23 and 23 * Screen.TwipsPerPixelY = 345. But your messagebox says
Title Bar HEIGHT (or thickness in you words): 345
and that is not exactly correct. It should have said 270 which is 18 pixels (I counted them in a large size picture of the Form).
Although I understand what your code is doing now I didn't understan it before because that 345 didn't make any sense to me as the height of the titlebar which is really 270 in Twips or 18 in Pixels.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: How to check if Form has a titlebar and borders
Yes, I understand except your titlebar height was incorrect.
Thanks for your help. I appreciate it.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.