Wednesday, July 02, 2008

Form Border and Title Bar of .Net WinForm

I came across a case where I've got to display a form right under another's control and found out that the Left and Top property is based on the Form, not the screen. Thus, the form border height and form title bar height must also be considered in the codes.

FormBorder_TitleBar

Here are the codes:

'in VB.NET
Dim BorderWidth as Integer = (Me.Width - Me.ClientSize.Width) / 2
Dim TitlebarHeight as Integer = Me.Height - Me.ClientSize.Height - 2 * BorderWidth
//in C#
int BorderWidth = (this.Width - this.ClientSize.Width) / 2;
int TitlebarHeight = this.Height - this.ClientSize.Height - 2 * BorderWidth;

Fortunately, other guy had solved the problem.

No comments: