Resetting controls

duelchamp1

Member
Joined
Aug 9, 2006
Messages
13
Programming Experience
Beginner
Hey guys

can anyone tell me how I can make a button that will reset all the radio buttons and labels on a form. here is what I got so far:

VB.NET:
If lblBody1.Visible = True Then
lblBody1.Visible = False
End If
 
If lblBody2.Visible = True Then
lblBody2.Visible = False
End If
 
If lblBody3.Visible = True Then
lblBody3.Visible = False
End If
 
If lbl2body1.Visible = True Then
lbl2body1.Visible = False
End If
 
If lbl2body2.Visible = True Then
lbl2body2.Visible = False
End If
 
If lbl2Body3.Visible = True Then
lbl2Body3.Visible = False
End If
 
If lblConc2.Visible = True Then
lblConc2.Visible = False
End If
 
If lblConc3.Visible = True Then
lblConc3.Visible = False
End If
 
If lblConc1.Visible = True Then
lblConc1.Visible = False
End If
 
If lblIntro1.Visible = True Then
lblIntro1.Visible = False
End If
 
If lblIntro2.Visible = True Then
lblIntro2.Visible = False
End If
 
If lblIntro3.Visible = True Then
lblIntro3.Visible = False
End If
 
If lbl1.Visible = True Then
lbl1.Visible = False
End If
 
If lbl2.Visible = True Then
lbl2.Visible = False
End If
 
If lbl3.Visible = True Then
lbl3.Visible = False
End If
 
If lbl4.Visible = True Then
lbl4.Visible = False
End If
 
If lbl5.Visible = True Then
lbl5.Visible = False
End If
 
If lbl6.Visible = True Then
lbl6.Visible = False
End If
 
If lbl7.Visible = True Then
lbl7.Visible = False
End If
 
If lbl8.Visible = True Then
lbl8.Visible = False
End If
 
If lbl9.Visible = True Then
lbl9.Visible = False
End If
 
If lbl10.Visible = True Then
lbl10.Visible = False
End If
 
If lbl11.Visible = True Then
lbl11.Visible = False
End If
 
If lbl2.Visible = True Then
lbl2.Visible = False
End If
 
radIntro1.Checked = False
radIntro2.Checked = False
radIntro3.Checked = False
radBody1.Checked = False
radBody2.Checked = False
radBody3.Checked = False
rad2body1.Checked = False
rad2body2.Checked = False
rad2body3.Checked = False
radConc1.Checked = False
radConc2.Checked = False
radConc3.Checked = False
Now this has been working howerver I have to click the button twice for it to clear everything (once for the labels and once for the radio buttons) any Ideas why? :confused:
 
Last edited by a moderator:
There's no point testing the Visible properties. Just go ahead and set them to False regardless. If they were False already you've lost nothing and the code is cleaner. Alternatively:
VB.NET:
Dim ctl As Control = Me.GetNextControl(Me, True)

While ctl IsNot Nothing
    If TypeOf ctl Is Label Then
        ctl.Visible = False
    ElseIf TypeOf ctl Is RadioButton Then
        DirectCast(ctl, RadioButton).Checked = False
    End If

    ctl = Me.GetNextControl(ctl, True)
End While
 
Back
Top