当我从子窗体中单击关闭按钮时,孩子将移动到屏幕然后整齐地关闭..但是当我通过父关闭按钮关闭它时,孩子将移动到屏幕然后冻结...为什么? ? tnx提前..
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 :(得分: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