Displaying a Panel Once Radio Button is Selected? VB 2008 Express

Discussion in 'Programming' started by FPForum, Jan 2, 2010.

  1. #1
    I've been searching google for a little bit now and not having much luck..I don't think this would be very hard to do but I am still a little new to VB..

    Basically, I have a 2 Panel's with some text boxes in them and I have 2 radio buttons...I want both panels to be hidden, but when RadioButton1 is selected I want Panel1 to show and vice versa, when RadioButton2 is selected I want Panel2 to display and Panel1 to be hidden.

    Can anyone shed some light on this for me as far as what would go in RadioButton1 and RadioButton2? Maybe post a URL to a tutorial or something? Thanks!
     
    FPForum, Jan 2, 2010 IP
  2. shall

    shall Member

    Messages:
    111
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #2
    I guess you can use a simple function, on events click on both radio buttons:
    Private Sub ToggleVisible()
            If (RadioButton1.Checked.Equals(True)) Then
                Panel1.Visible = True
                Panel2.Visible = False
            End If
    
            If (RadioButton2.Checked.Equals(True)) Then
                Panel1.Visible = False
                Panel2.Visible = True
            End If
    End Sub
    Code (markup):
     
    shall, Jan 2, 2010 IP
    FPForum likes this.
  3. NeoCambell

    NeoCambell Peon

    Messages:
    456
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Required steps are listed below.

    1. Make Visible property of Panel1 to true

    2. Make Visible property of Panel2 to false

    3. Double click on RadioButton1 and add the following code.
    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
    Panel1.Visible = True
    Panel2.Visible = False
    End Sub

    4. Double click on RadioButton2 and add the following code.
    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
    Panel1.Visible = False
    Panel2.Visible = True
    End Sub


    I assumed you have RadioButton1, RadioButton2, Panel1 and Panel2 on a form and RadioButton1 is associated with Panel1 and 2 with the other.

    To see whether this is working correctly, make sure you set the BorderStyle = FixedSingle of both panels and add few command buttons on panels.

    That's it.
     
    NeoCambell, Jan 2, 2010 IP
    FPForum likes this.
  4. FPForum

    FPForum Notable Member

    Messages:
    4,172
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    225
    Digital Goods:
    2
    #4
    Thanks for the input guys! Forgot about .Visible = True/False...Got it working :)

    Rep left for both of you!
     
    FPForum, Jan 2, 2010 IP