Question Checkbox/Picturebox

shinji2000

Member
Joined
Sep 2, 2011
Messages
6
Programming Experience
Beginner
I am creating an Interactive map which displays the facilities when the user clicks on the Checkbox, such as toilets. It will display all the toilet locations via PictureBoxes. I want to do this without having to write all this code?

Private Sub chkCash_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCash.CheckedChanged

If chkToilet.Checked And RadioButton1.Checked Then
PictureBox1.Visible = True
PictureBox2.Visible = True
PictureBox3.Visible = True
PictureBox4.Visible = True
Else
PictureBox1.Visible = False
PictureBox2.Visible = False
PictureBox3.Visible = False
PictureBox4.Visible = False
End If

If chkToilet.Checked And RadioButton2.Checked Then
PictureBox5.Visible = True
PictureBox6.Visible = True
PictureBox7.Visible = True
PictureBox8.Visible = True
PictureBox9.Visible = True
Else
PictureBox5.Visible = False
PictureBox6.Visible = False
PictureBox7.Visible = False
PictureBox8.Visible = False
PictureBox9.Visible = False
End If
End Sub
 
Please don't create more than one for each question or variation of that question. If you think that you've posted in the wrong forum then use the Report Post icon to send a request to the moderators to move your thread. Your other thread has been deleted.

First things first, there's never a justification for having names like PictureBox1 and RadioButton2. All those controls should be given meaningful names immediately.

As for the question:
Dim firstArray = {Me.PictureBox1, Me.PictureBox2, ...}
Dim secondArray = {Me.PictureBox5, Me.PictureBox6, ...}

Array.ForEach(firstArray, Sub(pb) pb.Visible = Me.CheckBox1.Checked AndAlso Me.RadioButton1.Checked)
Array.ForEach(secondArray, Sub(pb) pb.Visible = Me.CheckBox1.Checked AndAlso Me.RadioButton2.Checked)
 
Yeah it was a mistake. Where am I suppose to put this line of code?

Array.ForEach(firstArray, Sub(pb) pb.Visible = Me.CheckBox1.Checked AndAlso Me.RadioButton1.Checked)
Array.ForEach(secondArray, Sub(pb) pb.Visible = Me.CheckBox1.Checked AndAlso Me.RadioButton2.Checked)
 
I tried putting the code Array.ForEach under Private Sub chkCash_CheckedChanged and it doesn't work. Where am I suppose to put the Array.ForEach code?
 
You're supposed to put it wherever you want it executed. If you want it executed when the Checked property of chkCash changes then obviously you put it in the CheckedChanged event handler of chkCash. If you want it executed some other time then you put it somewhere else. So, you tell us, where does the code belong? You know what the code does. Where do you want that done? That's where the code goes.

As for the code, I can guarantee you that it does exactly what it's supposed to do. Each time it's executed, the first lot of PictureBoxes are displayed and the second lot hidden if the specified CheckBox and the first RadioButton are selected while the the first lot of PictureBoxes are hidden and the second lot displayed if the specified CheckBox and the second RadioButton are selected. I have tested it myself. As for whether or not it does what you want, that depends on whether that's what you want. That's what your original code does, so that's what I wrote.

Having said that, you haven't actually explained exactly what you want anywhere and your original code doesn't really look like it does anything sensible. Unless you're prepared to stop saying "it doesn't work" and actually provide some useful information, there's not much we can do for you. That useful information would include a FULL and CLEAR description of EXACTLY what you're trying to achieve, exactly how you're trying to achieve it (including code) and exactly what happens when you try (including error messages). Whenever you expect us to fill in the blanks, there's every chance that those blanks will be overlooked or filled in incorrectly.
 
Back
Top