|
-
Dec 30th, 2007, 03:53 PM
#1
Thread Starter
Member
[2005] Checkbox Checkstate
Hello,
When changing the .Checked or .CheckState property of a checkbox control in runtime, the CheckBox_CheckedChanged event is automatically called, for obvious reasons which I completely understand. Still, is there a way to somehow not let it do this?
-
Dec 30th, 2007, 04:05 PM
#2
Re: [2005] Checkbox Checkstate
As you know, thats exactly what its for, what are you trying to do ?
Casey.
-
Dec 30th, 2007, 04:13 PM
#3
Thread Starter
Member
Re: [2005] Checkbox Checkstate
I'm using the checkboxes as a list for tools. I'm working on a simple tile editor and I have these tools like pencil, color picker etc. I'm using checkboxes with appearance = button and with an image, no text. It's easy this way to see which is selected, and I don't need to create 2 different images or something for when the tool is selected.
So, when one of the checkboxes is clicked, I also need to uncheck the previously selected tool. When doing this, its checkedChanged event is called, which is not what I want.
-
Dec 30th, 2007, 04:35 PM
#4
Re: [2005] Checkbox Checkstate
If i understand you correctly, why dont you run the code in the mouseclick event so you know the user is actually selecting the checkbox and its not being deselected by code, even better, so you dont have to deselect the others is to use radiobuttons with the same appearance.
Casey.
-
Dec 30th, 2007, 05:01 PM
#5
Thread Starter
Member
-
Dec 30th, 2007, 05:57 PM
#6
Re: [2005] Checkbox Checkstate
You can't prevent the standard controls from accepting focus. You have to inherit the class of interest (e.g. Button, CheckBox, RadioButton) and add code to prevent it. It just so happens that I've done that myself for a recent project. Here's one I prepared earlier:
vb.net Code:
''' <summary> ''' A radio button control that cannot receive focus. ''' </summary> Public Class UnselectableRadioButton Inherits System.Windows.Forms.RadioButton #Region " Constructors " ''' <summary> ''' Initialises a new instance of the <see cref="UnselectableRadioButton"/> class. ''' </summary> Public Sub New() MyBase.New() 'The radio button cannot receive focus. Me.SetStyle(ControlStyles.Selectable, False) End Sub #End Region 'Constructors #Region " Methods " Protected Overrides Sub OnClick(ByVal e As System.EventArgs) MyBase.OnClick(e) End Sub #End Region 'Methods End Class
Once you add that class to your project and build it will appear in your Toolbox, so you can add instances to forms just as you do regular RadioButtons. You don't have to remove the regular RadioButtons you already have though. You can open the designer code file for your form and just do a Find & Replace to replace "System.Windows.Forms.RadioButton" with "UnselectableRadioButton".
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
|