/// <summary> /// Renders the text of the item specified on the event /// </summary> /// <param name="e">Event data and paint tools</param> public virtual void OnRenderRibbonItemText(RibbonItemBoundsEventArgs e) { }
public override void OnRenderRibbonItemText(RibbonItemBoundsEventArgs e) { if (e.Item is RibbonButton) { #region Button RibbonButton b = e.Item as RibbonButton; StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Near; if (e.Item.SizeMode == RibbonElementSizeMode.Large) { sf.Alignment = StringAlignment.Center; if (!string.IsNullOrEmpty(e.Item.Text) && !e.Item.Text.Contains(" ")) { sf.LineAlignment = StringAlignment.Near; } } using (SolidBrush brush = new SolidBrush(GetTextColor(e.Item.Enabled))) { e.Graphics.DrawString(e.Item.Text, e.Ribbon.Font, brush, e.Bounds, sf); } if (b.Style == RibbonButtonStyle.DropDown && b.SizeMode == RibbonElementSizeMode.Large) { DrawButtonDropDownArrow(e.Graphics, b, e.Bounds); } #endregion } else if (e.Item is RibbonSeparator) { #region Separator DrawSeparatorText(e, e.Item as RibbonSeparator); #endregion } else if (e.Item is RibbonTextBox) { #region Textbox DrawTextBoxText(e.Graphics, e); #endregion } else { #region Generic e.Graphics.DrawString(e.Item.Text, e.Ribbon.Font, SystemBrushes.ControlText, e.Bounds); #endregion } }
/// <summary> /// Draws the text of a RibbonTextbox /// </summary> /// <param name="g"></param> /// <param name="e"></param> public void DrawTextBoxText(Graphics g, RibbonItemBoundsEventArgs e) { RibbonTextBox t = e.Item as RibbonTextBox; StringFormat f = new StringFormat(); f.Alignment = StringAlignment.Near; f.LineAlignment = StringAlignment.Center; f.Trimming = StringTrimming.None; f.FormatFlags |= StringFormatFlags.NoWrap; e.Graphics.DrawString(t.TextBoxText, e.Ribbon.Font, t.Enabled ? SystemBrushes.ControlText : SystemBrushes.GrayText, t.TextBoxTextBounds, f); if (t.LabelVisible) { using (Brush b = new SolidBrush(GetTextColor(e.Item.Enabled))) { e.Graphics.DrawString(t.Text, e.Ribbon.Font, b, t.LabelBounds, f); } } }
public override void OnRenderRibbonItemImage(RibbonItemBoundsEventArgs e) { Image img = e.Item.Image; if (e.Item is RibbonButton) { if (!(e.Item.SizeMode == RibbonElementSizeMode.Large || e.Item.SizeMode == RibbonElementSizeMode.Overflow)) { img = (e.Item as RibbonButton).SmallImage; } } if (img != null) { if (!e.Item.Enabled) img = CreateDisabledImage(img); e.Graphics.DrawImage(img, e.Bounds.Location); } }
public void DrawSeparatorText(RibbonItemBoundsEventArgs e, RibbonSeparator sep) { using (Brush b = new SolidBrush(GetTextColor(sep.Enabled))) { e.Graphics.DrawString(sep.Text, new Font(sep.Owner.Font, FontStyle.Bold), b, e.Bounds); } }