private void DrawMenuItemCheck(Graphics g, DrawItemEventArgs e, MenuItem item, bool rightToLeft) { var rect = e.Bounds; rect.Location = new Point(0, 0); if (item.Checked) { rect.X++; rect.Y++; if (rightToLeft) { rect.X = rect.Right - (MenuBarWidth - 1); } rect.Width = (MenuBarWidth - 4); rect.Height -= 3; g.FillRectangle(StiBrushes.Selected, rect); g.DrawRectangle(StiPens.SelectedText, rect); var imageList = GetImageList(item); int imageIndex = GetImageIndex(item); if (!(imageList != null && imageIndex != -1 && imageIndex < imageList.Images.Count)) { if (rightToLeft) { StiControlPaint.DrawCheck(g, e.Bounds.Right - MenuBarWidth + ImageSize / 2, rect.Y + ImageSize / 2, true); } else { StiControlPaint.DrawCheck(g, ImageSize / 2, rect.Y + ImageSize / 2, true); } } } }
public static void DrawCheckBox(Graphics g, Rectangle rect, string text, Font font, Color foreColor, Color backColor, RightToLeft rightToLeft, bool isEnabled, bool isMouseOver, bool isFocused, bool drawLine, bool isChecked, CheckState checkState, Appearance appearance) { Rectangle checkRect = Rectangle.Empty; Rectangle textRect = Rectangle.Empty; textRect = new Rectangle(rect.X + 4, rect.Y, rect.Width - 4, rect.Height); if (rightToLeft == RightToLeft.No) { checkRect = new Rectangle(rect.X, rect.Y + (rect.Height - 12) / 2 - 1, 12, 12); } else { checkRect = new Rectangle(rect.Right - 15, rect.Y + (rect.Height - 12) / 2 - 1, 12, 12); } if (appearance == Appearance.Normal) { if (rightToLeft == RightToLeft.No) { textRect.X += 10; textRect.Width -= 10; } else { textRect.Width -= 16; } #region PaintLine if (drawLine) { using (Pen penLight = new Pen(StiColorUtils.Light(SystemColors.Control, 30)), penDark = new Pen(StiColorUtils.Dark(SystemColors.Control, 50))) { int strWidth = (int)g.MeasureString(text, font).Width; int posX = strWidth + 16 + rect.X; int posY = rect.Y + rect.Height / 2; if (posX < rect.Right) { g.DrawLine(penDark, posX, posY, rect.Right, posY); g.DrawLine(penLight, posX, posY + 1, rect.Right, posY + 1); } } } #endregion if (isEnabled) { using (var brush = new LinearGradientBrush(checkRect, StiColors.ContentDark, SystemColors.ControlLightLight, 45)) { g.FillRectangle(brush, checkRect); } } else { g.FillRectangle(SystemBrushes.Control, checkRect); } if (isEnabled && (isMouseOver || isFocused)) { g.DrawRectangle(StiPens.SelectedText, checkRect); } else { g.DrawRectangle(SystemPens.ControlDark, checkRect); } if (isChecked || checkState == CheckState.Indeterminate) { StiControlPaint.DrawCheck(g, checkRect.X + 6, checkRect.Y + 6, isEnabled); } if (checkState == CheckState.Indeterminate) { using (var brush = new SolidBrush(Color.FromArgb(200, SystemColors.Control))) { g.FillRectangle(brush, checkRect.X + 1, checkRect.Y + 1, checkRect.Width - 2, checkRect.Height - 2); } } #region Paint focus if (isFocused) { Rectangle focusRect = textRect; SizeF sizeText = g.MeasureString(text, font); focusRect.Width = (int)sizeText.Width; focusRect.Y = (focusRect.Height - ((int)sizeText.Height + 2)) / 2; focusRect.Height = (int)sizeText.Height + 2; if (rightToLeft == RightToLeft.Yes) { focusRect.X = textRect.Right - focusRect.Width; } ControlPaint.DrawFocusRectangle(g, focusRect); } #endregion } else { StiButton.DrawButton(g, rect, text, font, foreColor, backColor, null, -1, null, rightToLeft, false, isEnabled, isMouseOver, isChecked, false, isFocused, ContentAlignment.BottomCenter, ContentAlignment.MiddleCenter); } #region Paint string if (appearance == Appearance.Normal) { using (var sf = new StringFormat()) using (var foreBrush = new SolidBrush(foreColor)) { sf.FormatFlags = StringFormatFlags.NoWrap; sf.LineAlignment = StringAlignment.Center; sf.Trimming = StringTrimming.EllipsisCharacter; sf.HotkeyPrefix = HotkeyPrefix.Show; if (rightToLeft == RightToLeft.Yes) { sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } if (isEnabled) { g.DrawString(text, font, foreBrush, textRect, sf); } else { ControlPaint.DrawStringDisabled(g, text, font, backColor, textRect, sf); } } } #endregion }