So at present I am learning VB and I have a project in which I have to display a picture box based on:
Which radio box is checked
and
if a checkbox to make the picture box visible is checked. As someone who values clean, good code this is my code and it horrifies me. My question, is there some way to condense the following using cases or some other construct I don’t know in VB.net?
If CheckBox1.Checked = False Then
BooksPictureBox.Visible = False
MusicPictureBox.Visible = False
PeriodicalsPictureBox.Visible = False
CoffeeBarPictureBox.Visible = False
End If
If RadioButton1.Checked And CheckBox1.Checked = True Then
BooksPictureBox.Visible = True
MusicPictureBox.Visible = False
PeriodicalsPictureBox.Visible = False
CoffeeBarPictureBox.Visible = False
End If
If RadioButton2.Checked And CheckBox1.Checked = True Then
BooksPictureBox.Visible = False
MusicPictureBox.Visible = True
PeriodicalsPictureBox.Visible = False
CoffeeBarPictureBox.Visible = False
End If
If RadioButton3.Checked And CheckBox1.Checked = True Then
BooksPictureBox.Visible = False
MusicPictureBox.Visible = False
PeriodicalsPictureBox.Visible = True
CoffeeBarPictureBox.Visible = False
End If
If RadioButton4.Checked And CheckBox1.Checked = True Then
BooksPictureBox.Visible = False
MusicPictureBox.Visible = False
PeriodicalsPictureBox.Visible = False
CoffeeBarPictureBox.Visible = True
End If
Note- all the images stack on one another, and all of them start without being visible.
I would create a SUb that sets all picBoxes to not visible
Then another routine
Of course, an easier way would be to just have the image dynamically load based upon radio button selection.