public static void AddNumberBoxItem(ToolStripDropDown menu, LanguagableComponent component, string itemName, string itemTip, Bitmap itemIcon, bool enable, double Default, double Min, double Max, string valueName, int width = 150) { if (Max <= Min) { throw new ArgumentOutOfRangeException("Max less than Min!"); } bool flag = true; string English = "Value must be in " + Min.ToString() + " - " + Max.ToString() + ". Default is " + Default.ToString() + "."; string Chinese = "输入值域为 " + Min.ToString() + " - " + Max.ToString() + ", 默认为 " + Default.ToString() + "。"; string tip = itemTip + LanguagableComponent.GetTransLation(new string[] { English, Chinese }); ToolStripMenuItem item = CreateOneItem(itemName, tip, itemIcon, enable); var slider = new GH_DigitScroller { MinimumValue = (decimal)Min, MaximumValue = (decimal)Max, DecimalPlaces = 3, Value = (decimal)Default, Size = new Size(width, 24) }; slider.ValueChanged += Slider_ValueChanged; void Slider_ValueChanged(object sender, GH_DigitScrollerEventArgs e) { double result = (double)e.Value; result = result >= Min ? result : Min; result = result <= Max ? result : Max; component.SetValuePub(valueName, result, flag); flag = false; component.ExpireSolution(true); } WinFormPlus.AddLabelItem(item.DropDown, itemName, tip); GH_DocumentObject.Menu_AppendCustomItem(item.DropDown, slider); GH_DocumentObject.Menu_AppendItem(item.DropDown, LanguagableComponent.GetTransLation(new string[] { "Reset Number", "重置数值" }), resetClick, Properties.Resources.ResetLogo, true, false).ToolTipText = LanguagableComponent.GetTransLation(new string[] { "Click to reset Number.", "点击以重置数值。" }); void resetClick(object sender, EventArgs e) { component.SetValuePub(valueName, Default); component.ExpireSolution(true); } menu.Items.Add(item); }
/// <summary> /// Set a Loop Box item in Winform Menu /// </summary> /// <param name="menu"></param> /// <param name="component"></param> /// <param name="itemName">item's name for set infront of the name.</param> /// <param name="enable"></param> /// <param name="NameList"></param> /// <param name="IconList"></param> /// <param name="defaultIndex"></param> /// <param name="valueName"></param> public static void AddLoopBoexItem(ToolStripDropDown menu, LanguagableComponent component, string itemName, bool enable, string[] NameList, int defaultIndex, string valueName, Bitmap[] IconList = null) { if (defaultIndex > NameList.Length - 1) { throw new ArgumentOutOfRangeException("defaultIndex"); } if (IconList != null && IconList.Length != NameList.Length) { throw new ArgumentOutOfRangeException("IconList"); } int index = component.GetValuePub(valueName, defaultIndex); ToolStripMenuItem item = new ToolStripMenuItem(itemName + LanguagableComponent.GetTransLation(new string[] { ": ", ":" }) + NameList[index]); item.ToolTipText = LanguagableComponent.GetTransLation(new string[] { "Click to switch to ", "单击以切换到" }) + NameList[(index + 1) % NameList.Length]; if (IconList != null) { item.Image = IconList[index]; } item.Enabled = enable; item.Click += Item_Click; void Item_Click(object sender, EventArgs e) { component.SetValuePub(valueName, (index + 1) % NameList.Length); component.ExpireSolution(true); } menu.Items.Add(item); }
public static void AddTextItem(ToolStripDropDown menu, LanguagableComponent component, string itemName, string itemTip, Bitmap itemIcon, bool enable, string Default, string valueName, int width = 100) { bool flag = true; GH_DocumentObject.Menu_AppendTextItem(menu, itemName, BoxItemKeyDown, textchanged, true, width, true); void textchanged(GH_MenuTextBox sender, string newText) { component.SetValuePub(valueName, newText, flag); flag = false; component.ExpireSolution(true); } }
public static void AddColorBoxItem(ToolStripDropDown menu, LanguagableComponent component, string itemName, string itemTip, Bitmap itemIcon, bool enable, Color @default, string valueName) { bool flag = true; ToolStripMenuItem item = CreateOneItem(itemName, itemTip, itemIcon, enable); GH_DocumentObject.Menu_AppendColourPicker(item.DropDown, component.GetValuePub(valueName, @default), textcolorChange); void textcolorChange(GH_ColourPicker sender, GH_ColourPickerEventArgs e) { component.SetValuePub(valueName, e.Colour, flag); component.ExpireSolution(true); flag = false; } GH_DocumentObject.Menu_AppendItem(item.DropDown, LanguagableComponent.GetTransLation(new string[] { "Reset Color", "重置颜色" }), resetClick, Properties.Resources.ResetLogo, true, false).ToolTipText = LanguagableComponent.GetTransLation(new string[] { "Click to reset colors.", "点击以重置颜色。" }); void resetClick(object sender, EventArgs e) { component.SetValuePub(valueName, @default); component.ExpireSolution(true); } menu.Items.Add(item); }
public static void AddColorBoxItems(ToolStripDropDown menu, LanguagableComponent component, string itemName, string itemTip, Bitmap itemIcon, bool enable, ItemSet <Color>[] sets) { ToolStripMenuItem item = CreateOneItem(itemName, itemTip, itemIcon, enable); foreach (var set in sets) { AddColorBoxItem(item.DropDown, component, set); } GH_DocumentObject.Menu_AppendItem(item.DropDown, LanguagableComponent.GetTransLation(new string[] { "Reset Color", "重置颜色" }), resetClick, Properties.Resources.ResetLogo, true, false).ToolTipText = LanguagableComponent.GetTransLation(new string[] { "Click to reset colors.", "点击以重置颜色。" }); void resetClick(object sender, EventArgs e) { foreach (var set in sets) { component.SetValuePub(set.valueName, set.Default); } component.ExpireSolution(true); } menu.Items.Add(item); }