protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { if (e.Index == -1 || DesignMode) { return; } var colorRect = new Rectangle(e.Bounds.X + Dpi.ScaleX(2), e.Bounds.Y + Dpi.ScaleY(3), Dpi.ScaleX(12), Dpi.ScaleY(10)); var textBrush = Enabled ? UserBrushes.Text : UserBrushes.Disabled; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.FillRectangle(UserBrushes.Selection, e.Bounds); textBrush = UserBrushes.HighlightText; } else { e.Graphics.FillRectangle(UserBrushes.Window, e.Bounds); } var itemValue = this.Items[e.Index].ToString(); using (var colorBrush = new SolidBrush(itemValue == "Default" ? Color.FromKnownColor(DefaultColor) : Color.FromName(itemValue))) { if (Enabled) { e.Graphics.FillRectangle(colorBrush, colorRect); } e.Graphics.DrawRectangle(Enabled ? Pens.Black : Pens.Gray, colorRect); e.Graphics.DrawString(itemValue, Font, textBrush, new Point(e.Bounds.X + Dpi.ScaleX(18), e.Bounds.Y)); } }
protected override void OnMouseClick(MouseEventArgs e) { if (e.X > ClientSize.Width - Dpi.ScaleX(17)) { OnCloseRequested(EventArgs.Empty); return; } else if (e.X <= Dpi.ScaleX(12) + currentWidth) { contextMenu.Items.Clear(); for (var i = 0; i < Items.Count; i++) { var it = Items[i]; if (it != SelectedItem) { var mi = new ToolStripMenuItem { Text = it.Caption, Tag = it }; mi.Click += (o, a) => { var itm = (SwitchBarItem)((ToolStripMenuItem)o).Tag; SelectedIndex = Items.IndexOf(itm); }; contextMenu.Items.Add(mi); } } contextMenu.Renderer = new DocumentMenuRenderer(ClientSize.Width - Dpi.ScaleX(20)); contextMenu.Show(this, Dpi.ScaleX(3), Dpi.ScaleY(18)); } }
protected override void OnMouseMove(MouseEventArgs e) { if (e.X > ClientSize.Width - Dpi.ScaleX(17)) { if (hoverItem != 1) { hoverItem = 1; Refresh(); } } else if (e.X <= Dpi.ScaleX(12) + currentWidth) { if (hoverItem != 0) { hoverItem = 0; Refresh(); } } else if (hoverItem != -1) { hoverItem = -1; Refresh(); } base.OnMouseMove(e); }
private static Size InternalMeasureDropDown(ToolStripItemCollection items, bool root) { var conv = new KeysConverter(); var height = 0; var maxWidth = 0; var cm = items.Count > 0 && items[0].Owner is ContextMenuStrip; foreach (ToolStripItem it in items) { it.Font = Fonts.Menu; it.AutoSize = false; var sep = it is ToolStripSeparator; it.Height = Dpi.ScaleY(sep ? SEPAHEIGHT : ITEMHEIGHT); var sc = String.Empty; var mi = it as ToolStripMenuItem; if (mi != null && mi.ShortcutKeys != Keys.None) { sc = conv.ConvertToString(mi.ShortcutKeys) + " "; } var width = sep ? Dpi.ScaleX(10) : TextRenderer.MeasureText(it.Text + sc, it.Font).Width + Dpi.ScaleX(IsTopLevel(it) && !cm ? 10 : 20); if ((mi != null && !root && mi.DropDownItems.Count > 0) || cm) { width += Dpi.ScaleX(30); } it.Width = width; if (width > maxWidth) { maxWidth = width; } if (mi != null) { mi.DropDown.AutoSize = false; var size = InternalMeasureDropDown(mi.DropDownItems, false); mi.DropDown.Height = size.Height + Dpi.ScaleY(5); mi.DropDown.Width = size.Width; } height += it.Height; } if (!root || cm) { foreach (ToolStripItem it in items) { it.Width = maxWidth; } } return(new Size(maxWidth, height)); }
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) { if (e.Item.Selected) { var g = e.Graphics; var rect = new Rectangle(Dpi.ScaleX(1), Dpi.ScaleY(1), e.Item.Bounds.Width - Dpi.ScaleX(2), e.Item.Bounds.Height); g.FillRectangle(UserBrushes.Selection, rect); } }
public ColorPicker() { base.DropDownStyle = ComboBoxStyle.DropDownList; base.DropDownHeight = 320; base.Height = Dpi.ScaleY(21); base.MinimumSize = new System.Drawing.Size(Dpi.ScaleX(10), Dpi.ScaleY(21)); DrawMode = DrawMode.OwnerDrawVariable; SetStyle(ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); }
protected override void OnMouseClick(MouseEventArgs e) { if (e.Button == MouseButtons.Left && e.X < Dpi.ScaleX(16) + lastWidth) { GenerateMenu(); contextMenu.Font = Fonts.Menu; contextMenu.Renderer = new DocumentMenuRenderer(ClientSize.Width - Dpi.ScaleX(LABELS_WIDTH)); contextMenu.Show(this, new Point(Dpi.ScaleX(3), Dpi.ScaleY(HEIGHT - 2))); } }
protected override void OnPaint(PaintEventArgs e) { var rec = WideRendering ? new Rectangle(0, 0, ClientSize.Width - Dpi.ScaleX(1), ClientSize.Height - Dpi.ScaleX(1)) : new Rectangle(Dpi.ScaleX(1), 0, ClientSize.Width - Dpi.ScaleX(2), ClientSize.Height - Dpi.ScaleX(2)); using (var b = new SolidBrush(UserColors.Window)) e.Graphics.FillRectangle(b, rec); e.Graphics.DrawRectangle(UserPens.Border, rec); base.OnPaint(e); }
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) { if (e.Item.Selected) { var rect = new Rectangle(Dpi.ScaleX(1), Dpi.ScaleY(1), e.Item.Bounds.Width - Dpi.ScaleX(2), e.Item.Bounds.Height); e.Graphics.FillRectangle(UserBrushes.Selection, rect); } else if (e.Item is ToolStripMenuItem && ((ToolStripMenuItem)e.Item).DropDown.Visible) { var rect = new Rectangle(Dpi.ScaleX(1), Dpi.ScaleY(1), e.Item.Bounds.Width - Dpi.ScaleX(2), e.Item.Bounds.Height); e.Graphics.FillRectangle(UserBrushes.Selection, rect); } }
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) { var g = e.Graphics; var color = UserColors.Text; if (e.Item.Selected) { color = UserColors.HighlightText; } e.TextRectangle = new Rectangle(Dpi.ScaleX(15), e.TextRectangle.Y, Width - Dpi.ScaleX(18), Dpi.ScaleY(16)); TextRenderer.DrawText(e.Graphics, e.Text, Fonts.Menu, e.TextRectangle, color, TextFormatFlags.Left | TextFormatFlags.EndEllipsis); }
public ToolWindow() { InitializeComponent(); SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true); panel.BackColor = Color.White; panel.Paint += (o, e) => { var g = e.Graphics; g.DrawLine(UserPens.Border, 0, 0, 0, panel.ClientSize.Height); g.DrawLine(UserPens.Border, 0, panel.ClientSize.Height - Dpi.ScaleY(1), panel.ClientSize.Width, panel.ClientSize.Height - Dpi.ScaleY(1)); g.DrawLine(UserPens.Border, panel.ClientSize.Width - Dpi.ScaleX(1), 0, panel.ClientSize.Width - Dpi.ScaleX(1), panel.ClientSize.Height); }; switchBar.SelectedIndexChanged += SwitchBarSelectedIndexChanged; switchBar.CloseRequested += SwitchBarCloseRequested; panel.SetPadding(new Padding(Dpi.ScaleX(1), Dpi.ScaleY(5), Dpi.ScaleX(1), Dpi.ScaleX(2))); }
private int DrawItem(Graphics g, ToolbarItem item, int pos, bool sel) { var text = item.NewContent && !String.IsNullOrEmpty(item.ContentDescription) ? String.Format("{0} ({1})", item.Text, item.ContentDescription) : item.Text; var color = sel ? UserColors.HighlightText : UserColors.Text; var font = item.NewContent ? boldFont : Fonts.Menu; var tsize = TextRenderer.MeasureText(text, font); var width = tsize.Width; if (sel) { g.FillRectangle(UserBrushes.Selection, new Rectangle(pos - Dpi.ScaleX(5), Dpi.ScaleY(3), width + Dpi.ScaleX(10), tsize.Height + Dpi.ScaleY(2))); } TextRenderer.DrawText(g, text, font, new Rectangle(pos, Dpi.ScaleY(3), width, ClientSize.Height), color, TextFormatFlags.Left); return(width); }
protected override void OnMouseMove(MouseEventArgs e) { if (Items.Count > 1 && e.X <= Dpi.ScaleX(16) + lastWidth && e.Y < Dpi.ScaleY(HEIGHT)) { if (hoverItem != 0) { hoverItem = 0; using (var g = CreateGraphics()) PaintMain(g, fast: true); } } else if (hoverItem != -1) { hoverItem = -1; using (var g = CreateGraphics()) PaintMain(g, fast: true); } base.OnMouseMove(e); }
private void DrawNormalItem(ListItem item, DrawItemEventArgs e) { var caption = item.Text; var brush = default(Brush); if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { brush = UserBrushes.HighlightText; e.Graphics.FillRectangle(UserBrushes.Selection, e.Bounds); } else { brush = UserBrushes.Text; e.Graphics.FillRectangle(UserBrushes.Window, e.Bounds); } var captionSize = e.Graphics.MeasureString(caption, Font); e.Graphics.DrawString(caption, e.Font, brush, e.Bounds.X + Dpi.ScaleX(15), e.Bounds.Y + (e.Bounds.Height - captionSize.Height) / 2); }
protected override void OnPaint(PaintEventArgs e) { var g = e.Graphics; g.FillRectangle(UserBrushes.Window, ClientRectangle); var width = 0; var textColor = UserColors.Text; var corner = "Corner"; var cross = "Cross"; if (SelectedItem != null) { currentWidth = width = (Int32)g.MeasureString(SelectedItem.Caption, Fonts.Caption).Width; } if (hoverItem == 0 || contextMenu.Visible) { g.FillRectangle(UserBrushes.Selection, new Rectangle(Dpi.ScaleX(3), Dpi.ScaleY(4), Dpi.ScaleX(12) + width, Dpi.ScaleY(14))); textColor = UserColors.HighlightText; corner = "CornerWhite"; } else if (hoverItem == 1) { g.FillRectangle(UserBrushes.Selection, new Rectangle(ClientSize.Width - Dpi.ScaleX(17), Dpi.ScaleY(4), Dpi.ScaleX(14), Dpi.ScaleY(14))); cross = "CrossWhite"; } using (var bmp = Bitmaps.Load(corner)) g.DrawImage(bmp, new Rectangle(Dpi.ScaleX(5), Dpi.ScaleY(9), Dpi.ScaleX(bmp.Width), Dpi.ScaleY(bmp.Height))); using (var bmp = Bitmaps.Load(cross)) g.DrawImage(bmp, new Rectangle(ClientSize.Width - Dpi.ScaleX(15), Dpi.ScaleY(7), Dpi.ScaleX(bmp.Width), Dpi.ScaleY(bmp.Height))); g.DrawRectangle(UserPens.Border, new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - Dpi.ScaleX(1), ClientRectangle.Height)); if (SelectedItem != null) { TextRenderer.DrawText(g, SelectedItem.Caption, Fonts.Caption, new Rectangle(Dpi.ScaleX(14), 0, width + Dpi.ScaleY(20), ClientSize.Height), textColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Left | TextFormatFlags.EndEllipsis); } }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawLine(UserPens.Border, new Point(0, 0), new Point(ClientSize.Width, 0)); if (BottomBorder) { e.Graphics.DrawLine(UserPens.Border, new Point(0, ClientSize.Height - Dpi.ScaleY(1)), new Point(ClientSize.Width, ClientSize.Height - Dpi.ScaleY(1))); } if (LeftBorder) { e.Graphics.DrawLine(UserPens.Border, new Point(0, 0), new Point(0, ClientSize.Height - Dpi.ScaleY(1))); } if (RightBorder) { e.Graphics.DrawLine(UserPens.Border, new Point(ClientSize.Width - Dpi.ScaleX(1), 0), new Point(ClientSize.Width - Dpi.ScaleX(1), ClientSize.Height - Dpi.ScaleY(1))); } base.OnPaint(e); }
private void DrawHeader(ListGroup group, DrawItemEventArgs e) { var caption = group.Title; e.Graphics.FillRectangle(UserBrushes.Window, e.Bounds); using (var font = new Font(e.Font, FontStyle.Bold)) { if (group.Expanded) { e.Graphics.DrawImage(Bitmaps.Load("ArrowDownGray"), e.Bounds.X + Dpi.ScaleX(5), e.Bounds.Y + Dpi.ScaleY(7)); } else { e.Graphics.DrawImage(Bitmaps.Load("ArrowGray"), e.Bounds.X + Dpi.ScaleX(7), e.Bounds.Y + Dpi.ScaleY(5)); } var captionSize = e.Graphics.MeasureString(caption, font); e.Graphics.DrawString(caption, font, SystemBrushes.ControlText, e.Bounds.X + Dpi.ScaleX(14), e.Bounds.Y + (e.Bounds.Height - captionSize.Height) / 2); } }
protected override void OnPaint(PaintEventArgs e) { var g = e.Graphics; g.FillRectangle(UserBrushes.Menu, ClientRectangle); var shift = Dpi.ScaleX(11); foreach (var i in items) { var w = DrawItem(g, i, shift, i == selItem || i == hoverItem); i.Left = shift; i.Right = shift + w; shift += w + Dpi.ScaleX(10); } g.DrawLine(UserPens.Border, new Point(0, 0), new Point(ClientSize.Width, 0)); g.DrawLine(UserPens.Border, new Point(shift, 0), new Point(shift, ClientSize.Height)); var extraShift = Dpi.ScaleX(10); if (HighlightStatusString) { g.FillRectangle(UserBrushes.Window, new Rectangle(shift + Dpi.ScaleX(1), Dpi.ScaleY(1), ClientSize.Width - shift, ClientSize.Height)); if (StatusImage != null) { g.DrawImage(StatusImage, new Rectangle(shift + Dpi.ScaleX(10), Dpi.ScaleY(4), Dpi.ScaleX(StatusImage.Width), Dpi.ScaleY(StatusImage.Height))); } extraShift += Dpi.ScaleX(15); } var c = HighlightStatusString ? UserColors.Text : UserColors.Disabled; TextRenderer.DrawText(g, StatusString, Fonts.Text, new Rectangle(shift + extraShift, Dpi.ScaleY(3), ClientSize.Width - shift - Dpi.ScaleX(20), ClientSize.Height - Dpi.ScaleY(2)), c, TextFormatFlags.EndEllipsis); }
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) { var g = e.Graphics; var cm = e.ToolStrip is ContextMenuStrip; var x = IsTopLevel(e.Item) && !cm?Dpi.ScaleX(2) : Dpi.ScaleX(15); var y = IsTopLevel(e.Item) && !cm?Dpi.ScaleX(1) : e.TextRectangle.Y; var tsize = TextRenderer.MeasureText(e.Text, e.TextFont); if (e.Item.Text != e.Text) { x = e.ToolStrip.Width - tsize.Width - Dpi.ScaleX(2); } e.TextRectangle = new Rectangle(x, y, e.Item.Width - x, Dpi.ScaleY(16)); var flag = IsTopLevel(e.Item) && !cm ? TextFormatFlags.Top | TextFormatFlags.HorizontalCenter : TextFormatFlags.Default; var color = !e.Item.Enabled ? UserColors.Disabled : (e.Item.Selected || e.Item.Pressed ? UserColors.HighlightText : UserColors.Text); TextRenderer.DrawText(e.Graphics, e.Text, e.TextFont, e.TextRectangle, color, TextFormatFlags.Left | TextFormatFlags.EndEllipsis | flag); }
protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e) { using (var bmp = Bitmaps.Load("Arrow")) e.Graphics.DrawImage(bmp, new Rectangle(e.Item.Bounds.Width - Dpi.ScaleX(10), e.ArrowRectangle.Y + Dpi.ScaleY(7), Dpi.ScaleX(bmp.Width), Dpi.ScaleY(bmp.Height))); }
protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) { var g = e.Graphics; g.FillRectangle(UserBrushes.Menu, e.AffectedBounds); if (!(e.ToolStrip is MenuStrip)) { g.DrawRectangle(UserPens.Border, new Rectangle(0, 0, e.AffectedBounds.Width - Dpi.ScaleX(1), e.AffectedBounds.Height - Dpi.ScaleY(1))); } }
private void PaintMain(Graphics g, bool fast = false) { var textColor = UserColors.Text; var corner = "Corner"; var rect = new Rectangle(0, 0, ClientSize.Width - Dpi.ScaleX(1), Dpi.ScaleY(HEIGHT)); if (!fast) { var fullRect = new Rectangle(0, 0, ClientSize.Width - Dpi.ScaleX(1), ClientSize.Height - Dpi.ScaleY(1)); g.FillRectangle(UserBrushes.Window, rect); g.DrawRectangle(UserPens.Border, rect); g.DrawRectangle(UserPens.Border, fullRect); } var text = SelectedDocument != null ? SelectedDocument.Caption : String.Empty; var captionRect = new Rectangle(Dpi.ScaleX(15), 0, ClientSize.Width - Dpi.ScaleY(LABELS_WIDTH), Dpi.ScaleY(HEIGHT)); var flags = TextFormatFlags.Left | TextFormatFlags.PathEllipsis | TextFormatFlags.VerticalCenter; lastWidth = (Int32)g.MeasureString(text, Fonts.Header).Width; if (lastWidth > captionRect.Width) { lastWidth = captionRect.Width; } if (hoverItem == 0 || contextMenu.Visible) { textColor = UserColors.HighlightText; corner = "CornerWhite"; g.FillRectangle(UserBrushes.Selection, new Rectangle(Dpi.ScaleX(3), Dpi.ScaleY(4), Dpi.ScaleX(16) + lastWidth, Dpi.ScaleY(14))); } else if (hoverItem == -1 && fast) { g.FillRectangle(UserBrushes.Window, new Rectangle(Dpi.ScaleX(3), Dpi.ScaleY(4), Dpi.ScaleX(16) + lastWidth, Dpi.ScaleY(14))); } TextRenderer.DrawText(g, text, Fonts.Header, captionRect, textColor, flags); if (Items.Count > 1) { using (var bmp = Bitmaps.Load(corner)) g.DrawImage(bmp, new Rectangle(Dpi.ScaleX(5), Dpi.ScaleY(9), Dpi.ScaleX(bmp.Width), Dpi.ScaleY(bmp.Height))); } else if (Items.Count == 1) { using (var bmp = Bitmaps.Load("CornerDisabled")) g.DrawImage(bmp, new Rectangle(Dpi.ScaleX(7), Dpi.ScaleY(7), Dpi.ScaleX(bmp.Width), Dpi.ScaleY(bmp.Height))); } if (InfoBarVisible && !fast) { TextRenderer.DrawText(g, Overtype ? "OVR" : "INS", Fonts.Header, new Rectangle(ClientSize.Width - Dpi.ScaleX(32), 0, Dpi.ScaleX(30), Dpi.ScaleY(HEIGHT)), UserColors.Text, flags); TextRenderer.DrawText(g, Column.ToString(), Fonts.Menu, new Rectangle(ClientSize.Width - Dpi.ScaleX(68), 0, Dpi.ScaleX(25), Dpi.ScaleY(HEIGHT)), UserColors.Text, flags); TextRenderer.DrawText(g, "Col", Fonts.Header, new Rectangle(ClientSize.Width - Dpi.ScaleX(90), 0, Dpi.ScaleX(25), Dpi.ScaleY(20)), UserColors.Text, flags); TextRenderer.DrawText(g, Line.ToString(), Fonts.Menu, new Rectangle(ClientSize.Width - Dpi.ScaleX(123), 0, Dpi.ScaleX(35), Dpi.ScaleY(HEIGHT)), UserColors.Text, flags); TextRenderer.DrawText(g, "Line", Fonts.Header, new Rectangle(ClientSize.Width - Dpi.ScaleX(150), 0, Dpi.ScaleX(30), Dpi.ScaleY(HEIGHT)), UserColors.Text, flags); using (var bmp = Bitmaps.Load("Bounds")) g.DrawImage(bmp, new Rectangle(ClientSize.Width - Dpi.ScaleX(167), Dpi.ScaleY(5), Dpi.ScaleX(bmp.Width), Dpi.ScaleY(bmp.Height))); } }
protected override void OnPaint(PaintEventArgs e) { var g = e.Graphics; g.DrawRectangle(Pens.DarkGray, 0, switchBar.Height, ClientRectangle.Width - Dpi.ScaleX(1), ClientRectangle.Height - switchBar.Height - Dpi.ScaleY(1)); }
protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) { using (var bmp = Bitmaps.Load("Check")) e.Graphics.DrawImage(bmp, new Rectangle(e.ImageRectangle.X + Dpi.ScaleX(1), e.ImageRectangle.Y + Dpi.ScaleY(5), Dpi.ScaleX(bmp.Width), Dpi.ScaleY(bmp.Height))); }
public FlatPanel() { SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw, true); base.Padding = new Padding(Dpi.ScaleX(2), Dpi.ScaleY(2), Dpi.ScaleX(2), Dpi.ScaleY(2)); }