|
-
Mar 7th, 2015, 12:49 PM
#1
Thread Starter
New Member
[RESOLVED] How to use CheckBox as Picture(Box) Button?
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!
We make a living by what we get, but we make a life by what we give.
-
Mar 7th, 2015, 03:08 PM
#2
Re: How to use CheckBox as Picture(Box) Button?
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
-
Mar 8th, 2015, 02:18 AM
#3
Thread Starter
New Member
Re: How to use CheckBox as Picture(Box) Button?
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...
We make a living by what we get, but we make a life by what we give.
-
Mar 8th, 2015, 06:56 AM
#4
Re: How to use CheckBox as Picture(Box) Button?
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
-
Mar 8th, 2015, 11:15 AM
#5
Thread Starter
New Member
Re: How to use CheckBox as Picture(Box) Button?
If I don't use a CheckBox I am gettin an error:
Code:
'CheckBox1' is not declared. It may be inaccessible due to its protection level.
Anyway, I managed to do it with a hidden CheckBox.
How to uncheck CheckBox1 if CheckBox2 is checked? Currently, I am doin it as a click function of the PictureBox(es):
Code:
If CheckBox2.Checked Then
CheckBox1.Checked = "false"
Is there a better way?
Regards!
Last edited by Namorence; Mar 8th, 2015 at 11:21 AM.
We make a living by what we get, but we make a life by what we give.
-
Mar 8th, 2015, 11:18 AM
#6
Re: How to use CheckBox as Picture(Box) Button?
CheckBox1.Checked = Not CheckBox2.Checked
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|