MDI size and MDIClient Size after Layout event is not the same

  • Thread starter Thread starter Brian Tkatch
  • Start date Start date
B

Brian Tkatch

Not sure if this is the way it's supposed to be, but after a Layout
event on an MDI form, the form's new width is set, but the MDIClient's
width is not.

As an example, start a new Windows Application, and for the code use:

Public Class Form1

Dim TextBox1, TextBox2, TextBox3 As New TextBox
Dim The_MDIClient As MdiClient

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.IsMdiContainer = True

Me.Height = 600

TextBox1.Location = New System.Drawing.Point(1, 1)
TextBox2.Location = New System.Drawing.Point(71, 1)
TextBox3.Location = New System.Drawing.Point(121, 1)

TextBox1.Size = New System.Drawing.Size(70, Me.Height - 50)
TextBox2.Size = New System.Drawing.Size(50, Me.Height - 50)
TextBox3.Size = New System.Drawing.Size(50, Me.Height - 50)

TextBox1.Multiline = True
TextBox2.Multiline = True
TextBox3.Multiline = True

Me.Controls.Add(TextBox1)
Me.Controls.Add(TextBox2)
Me.Controls.Add(TextBox3)

For Each Current_Control As Control In Me.Controls
If TypeOf Current_Control Is MdiClient Then The_MDIClient =
Current_Control
Next

End Sub

Sub Show_Width(ByVal Sub_Name As String)

If The_MDIClient Is Nothing Then Exit Sub

TextBox1.Text += Mid$(Sub_Name, 7) + vbCrLf
TextBox2.Text += The_MDIClient.ClientRectangle.Width.ToString +
vbCrLf
TextBox3.Text += Me.ClientRectangle.Width.ToString + vbCrLf

End Sub

Private Sub Form1_ResizeBegin(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.ResizeBegin
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub
Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.ResizeEnd
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub
Private Sub Form1_Layout(ByVal sender As Object, ByVal e As
System.Windows.Forms.LayoutEventArgs) Handles Me.Layout
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub

End Class

Then resize.

Is this how it should be?

Also, is the MDIClient always the same amount less than the MDI form
itself? In this case, MDIClient.width is 4 less than Me.Width. If this
is constant, i can grab the difference in the Load event and in the
Layout event refer to Me.Width - whatever the difference is to get the
not-yet-updated MDIClient.Width.

B.
 
Brian said:
Not sure if this is the way it's supposed to be, but after a Layout
event on an MDI form, the form's new width is set, but the MDIClient's
width is not.

As an example, start a new Windows Application, and for the code use:

Public Class Form1

Dim TextBox1, TextBox2, TextBox3 As New TextBox
Dim The_MDIClient As MdiClient

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.IsMdiContainer = True

Me.Height = 600

TextBox1.Location = New System.Drawing.Point(1, 1)
TextBox2.Location = New System.Drawing.Point(71, 1)
TextBox3.Location = New System.Drawing.Point(121, 1)

TextBox1.Size = New System.Drawing.Size(70, Me.Height - 50)
TextBox2.Size = New System.Drawing.Size(50, Me.Height - 50)
TextBox3.Size = New System.Drawing.Size(50, Me.Height - 50)

TextBox1.Multiline = True
TextBox2.Multiline = True
TextBox3.Multiline = True

Me.Controls.Add(TextBox1)
Me.Controls.Add(TextBox2)
Me.Controls.Add(TextBox3)

For Each Current_Control As Control In Me.Controls
If TypeOf Current_Control Is MdiClient Then The_MDIClient =
Current_Control
Next

End Sub

Sub Show_Width(ByVal Sub_Name As String)

If The_MDIClient Is Nothing Then Exit Sub

TextBox1.Text += Mid$(Sub_Name, 7) + vbCrLf
TextBox2.Text += The_MDIClient.ClientRectangle.Width.ToString +
vbCrLf
TextBox3.Text += Me.ClientRectangle.Width.ToString + vbCrLf

End Sub

Private Sub Form1_ResizeBegin(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.ResizeBegin
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub
Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.ResizeEnd
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub
Private Sub Form1_Layout(ByVal sender As Object, ByVal e As
System.Windows.Forms.LayoutEventArgs) Handles Me.Layout
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub

End Class

Then resize.

Is this how it should be?

Also, is the MDIClient always the same amount less than the MDI form
itself? In this case, MDIClient.width is 4 less than Me.Width. If this
is constant, i can grab the difference in the Load event and in the
Layout event refer to Me.Width - whatever the difference is to get the
not-yet-updated MDIClient.Width.

B.

I think i found what to do.

After locating the MDIClient, i can use AddHandler to handle the layout
event of the MDIClient, and at that point, the width is known.

B.
 
To be specific, new Windows Application, go to form code, and paste
this:

Public Class Form1

Dim TextBox1, TextBox2, TextBox3 As New TextBox
Dim The_MDIClient As MdiClient

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.IsMdiContainer = True

Me.Height = 600

TextBox1.Location = New System.Drawing.Point(1, 1)
TextBox2.Location = New System.Drawing.Point(101, 1)
TextBox3.Location = New System.Drawing.Point(151, 1)

TextBox1.Size = New System.Drawing.Size(100, Me.Height - 50)
TextBox2.Size = New System.Drawing.Size(50, Me.Height - 50)
TextBox3.Size = New System.Drawing.Size(50, Me.Height - 50)

TextBox1.Multiline = True
TextBox2.Multiline = True
TextBox3.Multiline = True

Me.Controls.Add(TextBox1)
Me.Controls.Add(TextBox2)
Me.Controls.Add(TextBox3)

For Each Current_Control As Control In Me.Controls
If TypeOf Current_Control Is MdiClient Then
The_MDIClient = Current_Control
AddHandler The_MDIClient.Layout, AddressOf
MDIClient_Layout
AddHandler The_MDIClient.Resize, AddressOf
MDIClient_Resize
End If
Next

End Sub

Sub Show_Width(ByVal Sub_Name As String)

If The_MDIClient Is Nothing Then Exit Sub

TextBox1.Text += Sub_Name + vbCrLf
TextBox2.Text += The_MDIClient.ClientRectangle.Width.ToString +
vbCrLf
TextBox3.Text += Me.ClientRectangle.Width.ToString + vbCrLf

End Sub

Private Sub Form1_ResizeBegin(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.ResizeBegin
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub
Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.ResizeEnd
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub
Private Sub Form1_Layout(ByVal sender As Object, ByVal e As
System.Windows.Forms.LayoutEventArgs) Handles Me.Layout
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub

Private Sub MDIClient_Resize(ByVal sender As Object, ByVal e As
System.EventArgs)
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub
Private Sub MDIClient_Layout(ByVal sender As Object, ByVal e As
System.Windows.Forms.LayoutEventArgs)
Show_Width(System.Reflection.MethodBase.GetCurrentMethod.Name)
End Sub

End Class


B.
 
Back
Top