0

okay, this is my problem. I have a problem where when I select selectedindex = 2, when it is first run, the code doesn't work to display the panel, I have to select selectedindex = 1 before selecting selectedindex = 2.

The question is, how can I display the panels at selectedindex = 2 without having to select selectedindex = 1 first.

Here is the code that I used

    Private Sub choose(sender As Object, e As EventArgs) Handles choose1.SelectedIndexChanged
    If choose1.SelectedIndex = 1 Then
        luaspersegi.Visible = True
        kelilingpersegi.Visible = False
    ElseIf choose1.SelectedIndex = 2 Then
        kelilingpersegi.Visible = True
    End If

And this my result

https://prnt.sc/1196xy4

As you can see in the picture, when I select "Keliling" which is selectedindex = 2, the panel that I have hidden will appear but it will not appear. I have to select selectedindex = 1 first then select selectedindex = 2 to bring up the panel.

braX
  • 11,506
  • 5
  • 20
  • 33
  • If the two panels are one over the other (have the same position), you need to set one with _visible=true_ and the upper with _visible=false_. It seems that you leave the first panel always visible hiding the other panel – Steve Apr 10 '21 at 21:46
  • I've tried it but it doesn't work. – Ardian Maulana Apr 10 '21 at 22:44
  • 1
    https://stackoverflow.com/questions/9166319/cant-set-net-panel-to-visible/9166767#9166767 – Hans Passant Apr 10 '21 at 23:46

1 Answers1

0

When you create the panels. You need to make sure they do not overlap each other. Otherwise it means one of them is living in the other panel. Therefore if you set the parent invisible, the other one will be hidden also despite you call them visible.

What you need to do is to create 2 invisible panel and put them at different place as long as they are not overlapping each other then set the visibility by combo click and position them into the correct position.

Here comes the code

 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    If sender.selectedIndex = 0 Then

        Panel1.Left = 100
        Panel1.Top = 100
        ' Set the position for your panel

        Panel1.Visible = True
        Panel1.Width = 500
        Panel1.Height = 500

        ' set the size
        Panel2.Visible = False
        'make panel2 invisible

    ElseIf sender.selectedIndex = 1 Then

        Panel2.Left = 100
        Panel2.Top = 100

        Panel2.Visible = True
        Panel2.Width = 500
        Panel2.Height = 500
        Panel1.Visible = False
    End If
End Sub

Do mark it as answer if it helps you. I create a test program for the code and it works

Yat Fei Leong
  • 751
  • 1
  • 6
  • 10