public ToolStripItem CreateItem <TData>( DataItem <TData> dataItem, EventHandler handler, bool showToolTip = true, Keys shortcutKeys = Keys.None, bool showImage = false, ToolStripItemImageScaling imageScaling = ToolStripItemImageScaling.None ) { if (dataItem == null) { throw new ArgumentNullException(nameof(dataItem)); } var menuItem = new ToolStripMenuItem(dataItem.Name, null, handler) { ShortcutKeys = shortcutKeys, ImageScaling = imageScaling, Font = new Font(_fontFamilyName, _fontEmSize), }; _UpdateItem(menuItem, dataItem, showToolTip, showImage, false); return(menuItem); }
//--------------------------------------------------------------------- public ToolStripItem CreateItem <TDataItem, TData>( TData data, DataItemCollection <TDataItem, TData> collection, EventHandler handler, bool showToolTip = true, Keys shortcutKeys = Keys.None, bool showImage = false, ToolStripItemImageScaling imageScaling = ToolStripItemImageScaling.None ) where TDataItem : DataItem <TData> { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } var dataItem = collection[data]; if (dataItem == null) { throw new ArgumentException(string.Empty, nameof(data)); } var menuItem = new ToolStripMenuItem(dataItem.Name, null, handler) { ShortcutKeys = shortcutKeys, ImageScaling = imageScaling, Font = new Font(_fontFamilyName, _fontEmSize), }; _UpdateItem(menuItem, dataItem, showToolTip, showImage, false); return(menuItem); }
//--------------------------------------------------------------------- public ToolStripItem CreateDataClsItem <TData>( string text, TData data, EventHandler handler, string toolTip = "", Keys shortcutKeys = Keys.None, Image image = null, ToolStripItemImageScaling imageScaling = ToolStripItemImageScaling.None ) where TData : class { if (data == null) { throw new ArgumentNullException(nameof(data)); } var menuItem = new ToolStripMenuItem(text, image, handler) { ShortcutKeys = shortcutKeys, ImageScaling = imageScaling, Font = new Font(_fontFamilyName, _fontEmSize), }; _UpdateDataClsItem(menuItem, data, text, toolTip, image, true, false, false); return(menuItem); }
private void AddButton(TEnumType enumValue) { ulong num = Convert.ToUInt64(enumValue); if (num != 0) { Image reference = PdnResources.GetImageResource($"Icons.Enum.{typeof(TEnumType).Name}.{enumValue.ToString()}.png").Reference; if (reference != null) { ToolStripItemImageScaling sizeToFit = ToolStripItemImageScaling.SizeToFit; if (reference.Width > reference.Height) { if ((UIUtil.GetXScaleFactor() != 1f) || (UIUtil.GetYScaleFactor() != 1f)) { reference = new Bitmap(reference, UIUtil.ScaleSize(reference.Size)); } sizeToFit = ToolStripItemImageScaling.None; } ToolStripButton item = new ToolStripButton(PdnResources.GetString(typeof(TEnumType).Name + "." + enumValue.ToString(), KeyNotFoundResult.ReturnNull), reference, new EventHandler(this.OnButtonClick)) { Tag = num, ImageScaling = sizeToFit, DisplayStyle = ToolStripItemDisplayStyle.Image, AutoToolTip = true }; this.buttons.Add(item); } } }
public ToolStripDropDownItem CreateDropDownItem(string text, Image image, ToolStripItemImageScaling imageScaling, EventHandler handler) { return(new ToolStripMenuItem(text, image, handler) { ImageScaling = imageScaling, Font = new Font(_fontFamilyName, _fontEmSize) }); }
private void OnButtonAvailableChanged(object sender, EventArgs e) { ToolStripButton button = (ToolStripButton)sender; if ((button.Owner != null) && button.Available) { button.AvailableChanged -= new EventHandler(this.OnButtonAvailableChanged); TValue tag = (TValue)button.Tag; ImageResource resource = this.getImageForValueFn(tag); Image reference = resource?.Reference; ToolStripItemImageScaling sizeToFit = ToolStripItemImageScaling.SizeToFit; if (reference.Width > reference.Height) { if ((UIUtil.GetXScaleFactor() != 1f) || (UIUtil.GetYScaleFactor() != 1f)) { reference = new Bitmap(reference, UIUtil.ScaleSize(reference.Size)); } sizeToFit = ToolStripItemImageScaling.None; } button.ImageScaling = sizeToFit; button.Image = reference; } }
private void AddButton(LocalizedEnumValue enumValue) { Image reference = PdnResources.GetImageResource($"Icons.Enum.{typeof(TEnumType).Name}.{enumValue.EnumValueName}.png").Reference; if (reference != null) { ToolStripItemImageScaling sizeToFit = ToolStripItemImageScaling.SizeToFit; if (reference.Width > reference.Height) { if ((UIUtil.GetXScaleFactor() != 1f) || (UIUtil.GetYScaleFactor() != 1f)) { reference = new Bitmap(reference, UIUtil.ScaleSize(reference.Size)); } sizeToFit = ToolStripItemImageScaling.None; } ToolStripButton item = new ToolStripButton(enumValue.LocalizedName, reference, new EventHandler(this.OnButtonClick)) { Tag = enumValue.EnumValue, ImageScaling = sizeToFit, DisplayStyle = ToolStripItemDisplayStyle.Image }; this.buttons.Add(item); } }
protected ToolStripItem (string text, Image image, EventHandler onClick, string name) { this.alignment = ToolStripItemAlignment.Left; this.anchor = AnchorStyles.Left | AnchorStyles.Top; this.auto_size = true; this.auto_tool_tip = this.DefaultAutoToolTip; this.available = true; this.back_color = Color.Empty; this.background_image_layout = ImageLayout.Tile; this.can_select = true; this.display_style = this.DefaultDisplayStyle; this.dock = DockStyle.None; this.enabled = true; this.fore_color = Color.Empty; this.image = image; this.image_align = ContentAlignment.MiddleCenter; this.image_index = -1; this.image_key = string.Empty; this.image_scaling = ToolStripItemImageScaling.SizeToFit; this.image_transparent_color = Color.Empty; this.margin = this.DefaultMargin; this.merge_action = MergeAction.Append; this.merge_index = -1; this.name = name; this.overflow = ToolStripItemOverflow.AsNeeded; this.padding = this.DefaultPadding; this.placement = ToolStripItemPlacement.None; this.right_to_left = RightToLeft.Inherit; this.bounds.Size = this.DefaultSize; this.text = text; this.text_align = ContentAlignment.MiddleCenter; this.text_direction = DefaultTextDirection; this.text_image_relation = TextImageRelation.ImageBeforeText; this.visible = true; this.Click += onClick; OnLayout (new LayoutEventArgs (null, string.Empty)); }
protected ToolStripItem() { this.bounds = Rectangle.Empty; this.overflow = ToolStripItemOverflow.AsNeeded; this.placement = ToolStripItemPlacement.None; this.imageAlign = ContentAlignment.MiddleCenter; this.textAlign = ContentAlignment.MiddleCenter; this.textImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; this.state = new BitVector32(); this.imageTransparentColor = Color.Empty; this.imageScaling = ToolStripItemImageScaling.SizeToFit; this.cachedTextSize = System.Drawing.Size.Empty; this.displayStyle = ToolStripItemDisplayStyle.ImageAndText; this.state[((((((stateEnabled | stateAutoSize) | stateVisible) | stateContstructing) | stateSupportsItemClick) | stateInvalidMirroredImage) | stateMouseDownAndUpMustBeInSameItem) | stateUseAmbientMargin] = true; this.state[(((((((stateAllowDrop | stateMouseDownAndNoDrag) | stateSupportsRightClick) | statePressed) | stateSelected) | stateDisposed) | stateDoubleClickEnabled) | stateRightToLeftAutoMirrorImage) | stateSupportsSpaceKey] = false; this.SetAmbientMargin(); this.Size = this.DefaultSize; this.DisplayStyle = this.DefaultDisplayStyle; CommonProperties.SetAutoSize(this, true); this.state[stateContstructing] = false; this.AutoToolTip = this.DefaultAutoToolTip; }