RE: Problem when showing MdiChild form
- From: jetan@xxxxxxxxxxxxxxxxxxxx ("Jeffrey Tan[MSFT]")
- Date: Fri, 13 Jul 2007 03:02:13 GMT
Hi Lance,
During the discussion, the Winform confirmed that there is some painting
logic order wrong in showing the MDI child form. It seems that the
problematic drawing embeded deep in the Layout code. After spending a lot
effect to find a workaround, one Winform developer is able to find a
workaround. The workaround logic is like this:
"Basically, when you create the childform, set its position to (-1000,
-1000) (outside the screen). After it is set to visible, then you put it
back in the correct spot. When you set it to visible=false, then set it
outiside the screen again."
The modified repro sample is listed below, you may give it a try:
Public Class Form1
Inherits Windows.Forms.Form
Protected WithEvents Button1 As Windows.Forms.Button
Protected ChildForms() As Windows.Forms.Form
Public Sub New()
MyBase.New()
Me.IsMdiContainer = True
Me.Size = New Drawing.Size(800, 600)
Const n As Integer = 4
Const uBound As Integer = (n - 1)
Dim childForms(uBound) As Windows.Forms.Form
Dim position As Integer = 0
Const delta As Integer = 24
For i As Integer = 0 To uBound
childForms(i) = New Windows.Forms.Form
childForms(i).MdiParent = Me
childForms(i).FormBorderStyle = Windows.Forms.FormBorderStyle.None
childForms(i).ControlBox = False
childForms(i).StartPosition = FormStartPosition.Manual
childForms(i).Location = New Drawing.Point(position-1000, position-1000)
position += delta
Next i
Me.ChildForms = childForms
Me.Button1 = New Windows.Forms.Button
Me.Button1.Text = "Click Me"
Dim topPanel As New Windows.Forms.Panel
topPanel.Height = Me.Button1.Height
topPanel.Dock = DockStyle.Top
topPanel.Controls.Add(Me.Button1)
Me.Controls.Add(topPanel)
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
For i As Integer = 0 To Me.ChildForms.GetUpperBound(0)
Me.ChildForms(i).Visible = (Not Me.ChildForms(i).Visible)
If Me.ChildForms(i).Visible Then
Me.ChildForms(i).Location = New Drawing.Point(Me.ChildForms(i).Location.X +
1000, Me.ChildForms(i).Location.Y + 1000)
Else
Me.ChildForms(i).Location = New Drawing.Point(Me.ChildForms(i).Location.X -
1000, Me.ChildForms(i).Location.Y - 1000)
End If
Next i
End Sub
Protected Overrides Sub OnMdiChildActivate(ByVal e As System.EventArgs)
' The following simulates code that might be executed when an MdiChild is
activated, such as merging menus.
Dim duration As New System.TimeSpan(0, 0, 1)
Dim startTime As System.DateTime = System.DateTime.Now
While ((System.DateTime.Now - startTime) < duration)
End While
MyBase.OnMdiChildActivate(e)
End Sub
End Class
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- References:
- RE: Problem when showing MdiChild form
- From: "Jeffrey Tan[MSFT]"
- RE: Problem when showing MdiChild form
- From: "Jeffrey Tan[MSFT]"
- RE: Problem when showing MdiChild form
- Prev by Date: RE: Problem when showing MdiChild form
- Next by Date: Re: OO class design question (logic placement)...
- Previous by thread: RE: Problem when showing MdiChild form
- Next by thread: Re: Stopwatch Query
- Index(es):
Loading