Title bar height and Form border width of .Net form January 5, 2007
Posted by ssanjeevik in C#, VB.Net.trackback
When creating the MonthPicker control I faced one problem that i have to calculate the Title bar height and border with of the form. Because I need to show another form below the user control. I know left & top position of form which has the user control and know left & top of the user control within the form. But what about the titlebar height and form border the parent form has.
Click the above pic to view all the areas
After a while, i found a solution and the code is shown below
in C#
- int BorderWidth = (this.Width – this.ClientSize.Width) /2;
- int TitlebarHeight = this.Height – this.ClientSize.Height – 2 * BorderWidth;
in VB.Net
- Dim BorderWidth as Integer = (Me.Width – Me.ClientSize.Width) /2;
- Dim TitlebarHeight as Integer = Me.Height – Me.ClientSize.Height – 2 * BorderWidth;
Happy programming




thanks. you’ve given what i want
If I understand your requirements right, an easier solution would be to use the SystemInformation class:
int TitlebarHeight = SystemInformation.CaptionHeight;
int BorderWidth = SystemInformation.BorderSize;
I’ve found that with SystemInformation.BorderSize is faulty though. It took me over an hour tracking down the bug. The code above would give me a 3 for the border size while SystemInformation would only give me a 1. I suggest using the code above over SystemInformation.
BorderWidth = SystemInformation.FrameBorderSize.Width
returns the same value as
BorderWidth = (Me.Width – Me.ClientSize.Width) /2
Josh,
Is your control’s border style flat or 3D? There are two functions, BorderSize() and Border3DSize(). If you use the wrong one then you will not get your desired result.
Regardless, the first function provided by Peter is what I would recommend.
What happens when you get really drunk and hook up with a transexual and she tells you that you have the losses ass she has ever seen and sticks a hamster up your ass that some how gets lost during all the excitement and while all this is going on your wife comes home with a twelve inch black cock dildo and demands to strap it on and fuck the tranny? Man, I can’t believe all this actually happened! please help!
O, I almost forgot about my problem. So Before all this happened I was trying to figure out what size to make my Div is Dreamweaver for the header title bar. I was obviously unable to do so due to all the events I explained that happened but please let me know if you have any size(height, and width) ideas for me. Thanks! AAAH the wife is pulling out the dildo again… going to be a lllooonnngg day, hopefully i can walk straight after this time!
You give the programming community a bad name KockMonger Blowinstein