Man, I got the same bug. I was opening a form and setting the borderstyle
to none in the constructor. Then I set the form's size. Wouldn't you know
it, somehow the 19 pixels get added to the height of the form
(coincidentally , the height of the title bar in XP). Example I set the
form's height to be 300 from a config file in the constructor, after it
finishes loading it is 319!!!!!. Now mind you, there is no title bar
because the border style is none(set in the constructor also).
Ok so you think it has something to do with the title bar don't you. Nah,
it is the menu. The form has a menu on it, and if you use the
SystemInformati on.MenuHeight property you will see it is also 19 pixels.
When I removed the menu from the form, it calculates the height correctly. I
spent about 12 hours trying to figure this crap out. BIG BUG BIG BUG.
Just so you don't say I did not post a demo. I created a simple form and
added one menu item to it, I launched the form from a button on another form.
Here's the relevant functions. Try it first with the menu item. Then
Remove the menu item, and you will see that it screws up the size.
#Region " Windows Form Designer generated code "
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MenuItem1 As System.Windows. Forms.MenuItem
Friend WithEvents MainMenu1 As System.Windows. Forms.MainMenu
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.MenuItem1 = New System.Windows. Forms.MenuItem
Me.MainMenu1 = New System.Windows. Forms.MainMenu
'
'MenuItem1
'
Me.MenuItem1.In dex = 0
Me.MenuItem1.Te xt = "file"
'
'MainMenu1
'
Me.MainMenu1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( )
{Me.MenuItem1})
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 273)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.StartPositio n = System.Windows. Forms.FormStart Position.Manual
Me.Text = "Form1"
End Sub
#End Region
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
Me.SuspendLayou t()
'Add any initialization after the InitializeCompo nent() call
SetupForm()
Me.ResumeLayout ()
End Sub
Private Sub SetupForm()
Me.MinimizeBox = False
Me.MaximizeBox = False 'Me.MaximizeBox
Me.Text = ""
Me.FormBorderSt yle = FormBorderStyle .None
Me.Top = 20
Me.Left = 300
Me.Width = 200
Me.Height = 200
Me.ShowInTaskba r = False
End Sub
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Debug.WriteLine (Me.Height)
End Sub
"Xwire" wrote:
Can anyone explain why when i set the .ClientSize of a form, and then check
the .ClientSize when the resize event fires, it is slightly off, generally
20(varys) pixels in the height but not always. I have tried many things to
try to get the clientsize to set properly such as setting autoscale to false
among other things, but the client size will just not set properly. If I
check the client size immediatly after i set it it is correct but by the
time the resize event fires it is off.