2014-01-19 36 views
0

當我點擊從兒童形式的關閉按鈕孩子將移動到屏幕然後關閉整齊..但是,當我通過關閉父按鈕關閉孩子將移動到屏幕然後凍結...爲什麼? TNX提前..我得到了父母和我的孩子form..but當我關閉孩子它凍結..爲什麼?

Public Class ParentForm 

    Private Sub Show_Click(sender As Object, e As EventArgs) Handles button.Click 
     ChildForm.MdiParent = Me 
     ChildForm.Show() 
    End Sub 

    Private Sub Close_Click(sender As Object, e As EventArgs) Handles Login.Click 
     ChildForm.Refresh() 
     Do Until Me.Location.X = ChildForm.Width 
      ChildForm.Location = New Point(ChildForm.Location.X + 1, 250) 
     Loop 
     ChildForm.Close() 
    End Sub 
end class 

Public Class ChildForm 

    Private Sub ChildForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
     Me.Location = New Point(0, 250) 
     Me.Refresh() 
    end Sub 

    Sub anim() Handles Me.Shown 
     Me.Refresh() 
     Do Until Me.Location.X = 350 
      Me.Location = New Point(Me.Location.X + 1, 250) 
     Loop 
    End Sub 

    Private Sub Close_Click(sender As Object, e As EventArgs) Handles Close.Click 
     Do Until Me.Location.X = Me.Width + 1000 
      Me.Location = New Point(Me.Location.X + 1, 250) 
     Loop 
     Me.Close() 
    End Sub 

end class 

回答

0

因爲你在這一行中的錯誤:

所有的
Do Until Me.Location.X = ChildForm.Width 
    ChildForm.Location = New Point(ChildForm.Location.X + 1, 250) 
Loop 

首先,您使用了錯誤的對象(Me而不是ChildForm)。此外,你的邏輯似乎是不正確的;如果子表單的位置比其寬度更靠右(例如,如果子表單的寬度爲300,其X位置爲301),代碼將進入無限循環。嘗試更類似這樣的:

For i As Integer = 0 To ChildForm.Width 
    ChildForm.Left += 1 
Next 

這將使其右移其寬度並保持其在屏幕上的垂直位置。

編輯:哎呀,看來你想要父窗體關閉。在這種情況下,使用此代替:

For i As Integer = 0 To Me.Width 
    Me.Left += 1 
Next 
+0

我會試試它..tnx隊友! :d – user3211476

相關問題