Hello,
How to use CheckBox as Picture(Box) Button?
I'd like to set 3 separate images for the 3 different states of the the check button - 1 for unchecked, 1 for hover, 1 for checked.
Regards!
Printable View
Hello,
How to use CheckBox as Picture(Box) Button?
I'd like to set 3 separate images for the 3 different states of the the check button - 1 for unchecked, 1 for hover, 1 for checked.
Regards!
You could use events something like this (you would change the image rather than the colour);
Code:Private Sub SetPictureBox()
If (CheckBox1.Checked) Then
PictureBox1.BackColor = Color.Red
Else
PictureBox1.BackColor = Color.Blue
End If
End Sub
Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
SetPictureBox()
End Sub
Private Sub CheckBox1_MouseEnter(sender As System.Object, e As System.EventArgs) Handles CheckBox1.MouseEnter
PictureBox1.BackColor = Color.Green
End Sub
Private Sub CheckBox1_MouseLeave(sender As System.Object, e As System.EventArgs) Handles CheckBox1.MouseLeave
SetPictureBox()
End Sub
This worked perfectly, thanks!
How can I link the PictureBox to the CheckBox, I mean, when I click the ImageBox to act like I am clicking the CheckBox, etc...
You don't really need a checkbox in that case, but use the events associated with the PictureBox.
On PictureBox MouseClick do chagne the CheckBox1 state.
Use the PictureBox MouseEnter and MouseLeave events to run the same code as posted earlier.
So add these three events;
Code:
Private Sub PictureBox1_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox1.Click
CheckBox1.Checked = Not CheckBox1.Checked
End Sub
Private Sub PictureBox1_MouseEnter(sender As System.Object, e As System.EventArgs) Handles PictureBox1.MouseEnter
PictureBox1.BackColor = Color.Green
End Sub
Private Sub PictureBox1_MouseLeave(sender As System.Object, e As System.EventArgs) Handles PictureBox1.MouseLeave
SetPictureBox()
End Sub
If I don't use a CheckBox I am gettin an error:
Anyway, I managed to do it with a hidden CheckBox.Code:'CheckBox1' is not declared. It may be inaccessible due to its protection level.
How to uncheck CheckBox1 if CheckBox2 is checked? Currently, I am doin it as a click function of the PictureBox(es):
Is there a better way?Code:If CheckBox2.Checked Then
CheckBox1.Checked = "false"
Regards!
CheckBox1.Checked = Not CheckBox2.Checked