![]() ![]() ' with the CheckState property temporarily cleared to preventĭim currentState As CheckState = Me.CheckState ' If the Image property is not set, call the base OnPaint method ' selection is indicated only by the selection rectangle. ' remains unchanged, but the RadioButton is not displayed and the ' If the client sets the Image property, the selection behavior Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) ' where the check mark is normally displayed. ' Let the item paint itself, and then paint the RadioButton Int32 offset = (ContentRectangle.Height. Calculate the position at which to display the RadioButton. If (Checked) buttonState = RadioButtonState.CheckedDisabled Įlse buttonState = RadioButtonState.UncheckedDisabled If (Checked) buttonState = RadioButtonState.CheckedNormal If (Checked) buttonState = RadioButtonState.CheckedHot Įlse buttonState = RadioButtonState.UncheckedHot If (Checked) buttonState = RadioButtonState.CheckedPressed Įlse buttonState = RadioButtonState.UncheckedPressed RadioButtonState buttonState = RadioButtonState.UncheckedNormal Determine the correct state of the RadioButton. with the CheckState property temporarily cleared to preventĬheckState currentState = this.CheckState If the Image property is not set, call the base OnPaint method selection is indicated only by the selection rectangle. remains unchanged, but the RadioButton is not displayed and the If the client sets the Image property, the selection behavior Protected override void OnPaint(PaintEventArgs e) where the check mark is normally displayed. Let the item paint itself, and then paint the RadioButton Override the OnPaint method to replace the default check-mark with an option button by using the RadioButtonRenderer class. To modify the appearance of the option-button items ' the base method, which would toggle the value. ' If the item is already in the checked state, do not call Protected Overrides Sub OnClick(ByVal e As EventArgs) the base method, which would toggle the value. If the item is already in the checked state, do not call protected override void OnClick(EventArgs e) Override the OnClick method to ensure that clicking an item that has already been selected will not clear the selection. ' Only one item can be selected at a time, Tr圜ast(item, ToolStripRadioButtonMenuItem) ' Clear the checked state for all siblings.įor Each item As ToolStripItem In Parent.Itemsĭim radioItem As ToolStripRadioButtonMenuItem = _ If Not Checked OrElse Me.Parent Is Nothing Then Return ' parent has not yet been initialized, do nothing. ' If this item is no longer in the checked state or if its Protected Overrides Sub OnCheckedChanged(ByVal e As EventArgs) ![]() Only one item can be selected at a time, If (radioItem != null & radioItem != this & radioItem.Checked) Clear the checked state for all siblings.įoreach (ToolStripItem item in Parent.Items) If (!Checked || this.Parent = null) return parent has not yet been initialized, do nothing. If this item is no longer in the checked state or if its protected override void OnCheckedChanged(EventArgs e) Override the OnCheckedChanged method to clear the selection of the previously selected item when a new item is selected. ' Called by all constructors to initialize CheckOnClick. Called by all constructors to initialize CheckOnClick. Initialize the CheckOnClick property to true to enable item selection. To implement option-button selection behavior Additionally, this class overrides the Enabled property so that options on a submenu are disabled unless the parent item is selected. The ToolStripRadioButtonMenuItem class overrides members such as OnCheckedChanged and OnPaint to provide the selection behavior and appearance of option buttons. The following procedures describe how to implement this and additional functionality in a class that inherits the ToolStripMenuItem class. To implement basic option-button behavior, you must ensure that when an item is selected, you set the Checked property for the previously selected item to false. The Checked property indicates the current state of the item. When the CheckOnClick property of a menu item is true, users can click the item to toggle the display of a check mark. Although by default the ToolStripMenuItem class does not provide option-button behavior, the class does provide check-box behavior that you can customize to implement option-button behavior for menu items in a MenuStrip control. Option buttons, also known as radio buttons, are similar to check boxes except that users can select only one at a time. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |