Reputation: 3
I'm currently making a program and I'm adding a utilities form and I have buttons and panels. 1 button for 1 panel so I have code if they click a button while another panel is visible to hide and show the other panel. For some reason I have to click the button twice for it to change to a different panel, not sure why.
Code:
Private Sub btnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbout.Click
If pnlAbout.Visible = False Then
pnlAbout.Visible = True
Else
If pnlProfile.Visible = True Then
pnlProfile.Visible = False
pnlAbout.Visible = True
If pnlUpdates.Visible = True Then
pnlUpdates.Visible = False
pnlAbout.Visible = True
End If
End If
End If
End Sub
Private Sub btnProfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProfile.Click
If pnlProfile.Visible = False Then
pnlProfile.Visible = True
Else
If pnlAbout.Visible = True Then
pnlAbout.Visible = False
pnlProfile.Visible = True
If pnlUpdates.Visible = True Then
pnlUpdates.Visible = False
pnlProfile.Visible = True
End If
End If
End If
End Sub
Private Sub btnUpdates_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdates.Click
If pnlUpdates.Visible = False Then
pnlUpdates.Visible = True
Else
If pnlAbout.Visible = True Then
pnlAbout.Visible = False
pnlUpdates.Visible = True
If pnlProfile.Visible = True Then
pnlProfile.Visible = False
pnlUpdates.Visible = True
End If
End If
End If
End Sub
Upvotes: 0
Views: 3767
Reputation: 1
Your code can be Summarize into this:
private sub button1_click(Byval sender as System.Object, ByVAl e AS System.EventArgs)Handles buttonUpdates.click
panel1.Visible = true
panel2.Visible = false
End Sub
Upvotes: 0
Reputation: 7204
Your code can be summarized to:
Private Sub btnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbout.Click
pnlAbout.Visible = True
pnlProfile.Visible = False
pnlUpdates.Visible = False
End Sub
Private Sub btnProfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProfile.Click
pnlAbout.Visible = False
pnlProfile.Visible = True
pnlUpdates.Visible = False
End Sub
Private Sub btnUpdates_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdates.Click
pnlAbout.Visible = False
pnlProfile.Visible = False
pnlUpdates.Visible = True
End Sub
You need twice cause the first click makes the correct panel visible and the second (if you are lucky) the one which was visible not visible.
Upvotes: 1