Angel
Angel

Reputation: 87

how to bring the form in front after closing another form in vb.net

i have my main form and it has a button that will show the second form and it enabled = false the first form.

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

End Sub

when you click the button on the second form it will go back to the first form and it will enabled = 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

what my problem is that when i click "back" button the second form is gone but the first form is sent at the back of the current window, you still need to minimize that particular window to see the form 1 again.

here is my sample image. sample image

Upvotes: 1

Views: 1143

Answers (1)

SSS
SSS

Reputation: 5393

Have you tried making the second form a "modal" form, with 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

Upvotes: 1

Related Questions