algorithmic modeling for Rhino
Hi All,
I am struggling to find a way to keep layout of menu (actually a sub menu) in a custom component. As shown in the image, the sub menu loose the nice layout, especially the column icons and tick mark is displayed. Could any one help me with this? Code is attached. A ToolStripMenuItem is added to main menu and its DropDown property is assigned to a new ToolStropDropDown.
Thank you.
Xiaoming
public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
{
Menu_AppendSeparator(menu);
//add view option
ToolStripMenuItem previewDropDownMenuItem = new ToolStripMenuItem();
previewDropDownMenuItem.Text = "Preview Option";
ToolStripDropDown previewOptionsDropDown = new ToolStripDropDown();
previewIES = new ToolStripMenuItem();
previewIES.Text = "Candela Profile";//Preview with candela profile
previewIES.Checked = true;//use check display for this sub men
if (displayMethod==0)
previewIES.CheckState = System.Windows.Forms.CheckState.Checked;
else
previewIES.CheckState = System.Windows.Forms.CheckState.Unchecked;
previewIES.Click += new EventHandler(displayMethod_Changed);
previewOptionsDropDown.Items.Add(previewIES);
previewCone = new ToolStripMenuItem();
previewCone.Text = "Half Power Cone";//
previewCone.Checked = true;//use check display for this sub men
if (displayMethod == 0)
previewCone.CheckState = System.Windows.Forms.CheckState.Unchecked;
else
previewCone.CheckState = System.Windows.Forms.CheckState.Checked;
previewCone.Click += new EventHandler(displayMethod_Changed);
previewOptionsDropDown.Items.Add(previewCone);
previewOptionsDropDown.LayoutStyle = menu.LayoutStyle;
previewDropDownMenuItem.DropDown = previewOptionsDropDown;
menu.Items.Add(previewDropDownMenuItem);
GH_DocumentObject.Menu_AppendTextItem(previewOptionsDropDown, iesDisplaySize.ToString(), new GH_MenuTextBox.KeyDownEventHandler(PreviewSize_keydown), new GH_MenuTextBox.TextChangedEventHandler(PreviewSize_TextChange), true);
GH_DocumentObject.Menu_AppendItem(menu, "Load IES", new EventHandler(this.Menu_LoadIESClicked), true);//load IES file
Menu_AppendSeparator(menu);
}
Tags:
Any ideas? Is it layout style of the new defined ToolStripDropDown previewOptionsDropDown?
Can you try adding an icon to your menu items?
Hi David,
Thank you for your reply. I tried to have a tick mark displayed for the sub menu items. When I add a item to the main menu, I could define ToolStripMenuItem.previewIES.Checked to show the tick mark. Can I do the same for the sub menu items? I tried add an icon with ToolStripMenuItem.Image. Then it display the icon instead of the tick mark.
Xiaoming
The AppendMenuXXX methods on GH_DocumentObject have overloads that allow for the setting of icons, tickmarks and handlers. I find it easier to use those methods than writing the menu code from scratch every time.
Thank you! I finally got it. To add a item to sub menu, I simply
GH_DocumentObject.Menu_AppendTextItem(MainMenuItem.DropDown,...)
This is a much better way. Thank you!
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by