- CHECK MENU ITEM MENUSTRIP WINFORMS HOW TO
- CHECK MENU ITEM MENUSTRIP WINFORMS ZIP FILE
- CHECK MENU ITEM MENUSTRIP WINFORMS CODE
- CHECK MENU ITEM MENUSTRIP WINFORMS PROFESSIONAL
/ If menu item belongs to the radio group, this override ensures proper functionality The following override of OnClick method reinforces the rule that only one item within the same (e.Graphics, new Point(radioButtonX, radioButtonY), state) Draw RadioButton in proper state (Checked/Unchecked Hot/Normal/Pressed) State = RadioButtonState.UncheckedNormal State = RadioButtonState.UncheckedPressed RadioButtonState state = RadioButtonState.CheckedNormal (ContentRectangle.Height - radioButtonSize.Height) / 2 (e.Graphics, RadioButtonState.CheckedNormal) Size radioButtonSize = RadioButtonRenderer.GetGlyphSize If ( (CheckMarkDisplayStyle = CheckMarkDisplayStyle.RadioButton)) if CheckMarkDisplayStyle is equal RadioButton additional paining or radioButton is needed
Protected override void OnPaint(PaintEventArgs e) / Standard event arguments for OnPaint method. / if CheckMarkDisplayStyle is equal RadioButton OnPaint override paints radio button images.
CHECK MENU ITEM MENUSTRIP WINFORMS CODE
The following override code ensures display of RadioButton image:
CHECK MENU ITEM MENUSTRIP WINFORMS ZIP FILE
Otherwise item check mark is replaced with RadioButton image.ĬheckMarkDisplayStyle is defined as follows:īelow are presented essential pieces of code responsible for enhanced functionality.įor details, please refer to the attached zip file with the source code. If set to CheckMarkDisplayStyle.Checkbox, TollStripEnhancedMenuItem behaves identically as "regular" ToolStripMenuItem. If you want to have multiple groups in your menu, you should set this property accordingly.ĬheckMarkDisplayStyle CheckMarkDisplayStyleĭefault value is CheckMarkDisplayStyle.RadioButton. Group (in similar way as GroupBox groups RadioButton controls).Īll menu items with identical RadioButtonGroupName belong to the same group.ĭefault RadioButtonGroupName is an empty string. This property provides means to show several menu items as menu items ToolStripEnhancedMenuItem defines the following additional properties: ToolStripEnhancedMenuItem - Menu item with the RadioButton as the check mark Additionally to parent classįunctionality it provides options for text scrolling. It acts as MenuItemSeparator with additional ability to display static text.įrom ToolStripEnhancedMenuItem. It inherits all functionality of ToolStripMenuItem and additionally provides the following functional enhancements:Ībility to display RadioButton image in place of CheckBox.Ībility to group items into RadiButtonGroup to ensure that only one item within the group can be selected. Code AnatomyĮnhancedContextMenu library consists of three components: That means that the only thing I needed to change was howĮnhanced ToolStripMenuItem paints itself, what didn't look like a lot of work. Present itself in GUI (extra text for separator, radio button as check mark or scrolling text). Only real difference is how enhanced ToolStripMenuItem should My reasoning for this solution was the following: base ToolStripMenuItem class This article is presenting another approach:Ĭomponents inherited from ToolStripMenuItem class. I used this method few times and found it temperamental and buggy,
CHECK MENU ITEM MENUSTRIP WINFORMS HOW TO
There are plenty of Internet articles and examples showing how to do it. One way is to use ToolStripControlHost object to wrap any WinForms control as ToolStrip insertable control. Very often, I needed to add into MenuStrip controls not present on the list.įor example, I wanted to display radio button instead of check box, have descriptive separators and scrollable (marquee) menu items (see animated image below).įortunately, there are ways to enrich set of objects that can be used as items in the ToolStrip. It allows to pick item from drop-down combo box. Simple, usually gray line to separate distinct groups of menu items. You can have:īasic menu element: text you can click on to trigger desired action it can have the following optional elements: image, shortcut and checkbox. As designed by Microsoft, number of menu items you can chose from is short.
CHECK MENU ITEM MENUSTRIP WINFORMS PROFESSIONAL
In my professional life, I have to do a lot of GUI development and MenuStrip, especially ContextMenuStrip is one of WinForms controls I use probably most often.