我的申请有两种形式。我想将一个表格放在另一个表格前面。我想了解为什么这段代码不起作用:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Location = New Point(200, 200)
Form2.Location = New Point(200, 200)
Form2.BringToFront()
End Sub
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Form2.Visible = True
Me.Text = Form2.Location.X
End Sub
End Class
当我运行代码时,第二个表单位于屏幕上的随机位置。
如果我删除Form2.Visible语句:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Location = New Point(200, 200)
Form2.Location = New Point(200, 200)
Form2.BringToFront()
End Sub
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Me.Text = Form2.Location.X
End Sub
End Class
第二种形式似乎定位正确,但是,它是不可见的。
我敢肯定,有解决方法。我只是想了解为什么这么简单的事情不能按预期工作。