如何在vb.net中关闭另一个表单后将表单放在前面

时间:2015-12-11 05:22:37

标签: vb.net forms

我有我的主表单,它有一个显示第二个表单的按钮,它启用= false第一个表单。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Form2.Show()
    Me.Enabled = False

End Sub

当您单击第二个表单上的按钮时,它将返回到第一个表单,它将启用= true。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.Hide()
    Form1.Enabled = True

End Sub

我的问题是,当我单击“后退”按钮时,第二个表单消失但第一个表单在当前窗口的后面发送,您仍然需要最小化该特定窗口以再次查看表单1。

这是我的示例图片。 sample image

1 个答案:

答案 0 :(得分:1)

您是否尝试使用ShowDialog

将第二种形式设为“模态”形式
Public Class Form1

  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If Form2.ShowDialog() = Windows.Forms.DialogResult.OK Then
      MsgBox("OK!")
    Else
      MsgBox("Cancelled :-(")
    End If
  End Sub

End Class


Public Class Form2
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Me.DialogResult = Windows.Forms.DialogResult.OK
  End Sub

  Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Me.DialogResult = Windows.Forms.DialogResult.Cancel
  End Sub
End Class