protected void PaintHeader(Graphics g) { if (this.headerHeight == 0) { return; } Rectangle buttonRect = this.ButtonRectangle; CheckBoxState activeState = CheckBoxState.UncheckedDisabled; ExpandBoxState expandState = ExpandBoxState.ExpandDisabled; bool parentExpand = this.ParentUseIndentChildExpand; if (!parentExpand && (this.Hints & HintFlags.HasExpandCheck) != HintFlags.None) { if (this.Enabled && this.CanExpand && (this.Hints & HintFlags.ExpandEnabled) != HintFlags.None) { if (!this.Expanded) { if (this.expandCheckPressed) { expandState = ExpandBoxState.ExpandPressed; } else if (this.expandCheckHovered) { expandState = ExpandBoxState.ExpandHot; } else { expandState = ExpandBoxState.ExpandNormal; } } else { if (this.expandCheckPressed) { expandState = ExpandBoxState.CollapsePressed; } else if (this.expandCheckHovered) { expandState = ExpandBoxState.CollapseHot; } else { expandState = ExpandBoxState.CollapseNormal; } } } else { if (this.Expanded) { expandState = ExpandBoxState.ExpandDisabled; } else { expandState = ExpandBoxState.CollapseDisabled; } } } if ((this.Hints & HintFlags.HasActiveCheck) != HintFlags.None) { if (this.Enabled && !this.ReadOnly && (this.Hints & HintFlags.ActiveEnabled) != HintFlags.None) { if (this.Active) { if (this.activeCheckPressed) { activeState = CheckBoxState.CheckedPressed; } else if (this.activeCheckHovered) { activeState = CheckBoxState.CheckedHot; } else { activeState = CheckBoxState.CheckedNormal; } } else { if (this.activeCheckPressed) { activeState = CheckBoxState.UncheckedPressed; } else if (this.activeCheckHovered) { activeState = CheckBoxState.UncheckedHot; } else { activeState = CheckBoxState.UncheckedNormal; } } } else { if (this.Active) { activeState = CheckBoxState.CheckedDisabled; } else { activeState = CheckBoxState.UncheckedDisabled; } } } Rectangle iconRect; if (this.headerIcon != null) { iconRect = new Rectangle( this.activeCheckRect.Right + 2, this.headerRect.Y + this.headerRect.Height / 2 - this.headerIcon.Height / 2, this.headerIcon.Width, this.headerIcon.Height); } else { iconRect = new Rectangle(this.activeCheckRect.Right, this.headerRect.Y, 0, 0); } Rectangle textRect = new Rectangle( iconRect.Right, this.headerRect.Y, this.headerRect.Width - buttonRect.Width - iconRect.Width - this.expandCheckRect.Width - this.activeCheckRect.Width - 2, this.headerRect.Height); Rectangle nameTextRect; Rectangle valueTextRect; if (!string.IsNullOrEmpty(this.PropertyName) && !string.IsNullOrEmpty(this.headerValueText)) { int nameWidth; nameWidth = this.NameLabelWidth - (textRect.X - this.headerRect.X); nameTextRect = new Rectangle(textRect.X, textRect.Y, nameWidth, textRect.Height); valueTextRect = new Rectangle(textRect.X + nameWidth, textRect.Y, textRect.Width - nameWidth, textRect.Height); } else if (!string.IsNullOrEmpty(this.headerValueText)) { nameTextRect = new Rectangle(textRect.X, textRect.Y, 0, 0); valueTextRect = textRect; } else { nameTextRect = textRect; valueTextRect = new Rectangle(textRect.X, textRect.Y, 0, 0); } bool focusBg = this.Focused || (this is IPopupControlHost && (this as IPopupControlHost).IsDropDownOpened); bool adaptBgColor = this.headerStyle == GroupHeaderStyle.Flat || this.headerStyle == GroupHeaderStyle.Simple; Color headerBgColor = this.ControlRenderer.GetBackgroundColor(this.headerColor.Value, focusBg && adaptBgColor, this.Location.X); GroupedPropertyEditor.DrawGroupHeaderBackground(g, this.headerRect, headerBgColor, this.headerStyle); if (focusBg && !adaptBgColor) { this.ControlRenderer.DrawBorder(g, this.headerRect, Drawing.BorderStyle.Simple, BorderState.Normal); } if (!parentExpand && (this.Hints & HintFlags.HasExpandCheck) != HintFlags.None) { this.ControlRenderer.DrawExpandBox(g, this.expandCheckRect.Location, expandState); } if ((this.Hints & HintFlags.HasActiveCheck) != HintFlags.None) { this.ControlRenderer.DrawCheckBox(g, this.activeCheckRect.Location, activeState); } if (this.headerIcon != null) { g.DrawImage(this.Enabled ? this.headerIcon.Normal : this.headerIcon.Disabled, iconRect); } this.ControlRenderer.DrawStringLine(g, this.PropertyName, this.ValueModified ? this.ControlRenderer.FontBold : this.ControlRenderer.FontRegular, nameTextRect, this.Enabled && !this.NonPublic ? this.ControlRenderer.ColorText : this.ControlRenderer.ColorGrayText); this.ControlRenderer.DrawStringLine(g, this.headerValueText, this.ValueModified ? this.ControlRenderer.FontBold : this.ControlRenderer.FontRegular, valueTextRect, this.Enabled ? this.ControlRenderer.ColorText : this.ControlRenderer.ColorGrayText); }
private void InitExpandBox(ExpandBoxState state) { if (expandBoxImages != null && expandBoxImages.ContainsKey(state)) return; if (expandBoxImages == null) expandBoxImages = new Dictionary<ExpandBoxState,Bitmap>(); Bitmap image = new Bitmap(CheckBoxSize.Width, CheckBoxSize.Height); using (Graphics checkBoxGraphics = Graphics.FromImage(image)) { Color plusSignColor; Pen expandLineShadowPen; Pen expandLinePen; if (state == ExpandBoxState.ExpandNormal || state == ExpandBoxState.CollapseNormal) { plusSignColor = Color.FromArgb(24, 32, 82); expandLinePen = new Pen(Color.FromArgb(255, plusSignColor)); expandLineShadowPen = new Pen(Color.FromArgb(64, plusSignColor)); CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); } else if (state == ExpandBoxState.ExpandHot || state == ExpandBoxState.CollapseHot) { plusSignColor = Color.FromArgb(32, 48, 123); expandLinePen = new Pen(Color.FromArgb(255, plusSignColor)); expandLineShadowPen = new Pen(Color.FromArgb(64, plusSignColor)); CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedHot); } else if (state == ExpandBoxState.ExpandPressed || state == ExpandBoxState.CollapsePressed) { plusSignColor = Color.FromArgb(48, 64, 164); expandLinePen = new Pen(Color.FromArgb(255, plusSignColor)); expandLineShadowPen = new Pen(Color.FromArgb(96, plusSignColor)); CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedPressed); } else { plusSignColor = Color.FromArgb(24, 28, 41); expandLinePen = new Pen(Color.FromArgb(128, plusSignColor)); expandLineShadowPen = new Pen(Color.FromArgb(32, plusSignColor)); CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedDisabled); } // Plus Shadow checkBoxGraphics.DrawLine(expandLineShadowPen, 3, image.Height / 2 + 1, image.Width - 4, image.Height / 2 + 1); checkBoxGraphics.DrawLine(expandLineShadowPen, 3, image.Height / 2 - 1, image.Width - 4, image.Height / 2 - 1); if (state == ExpandBoxState.ExpandDisabled || state == ExpandBoxState.ExpandHot || state == ExpandBoxState.ExpandNormal || state == ExpandBoxState.ExpandPressed) { checkBoxGraphics.DrawLine(expandLineShadowPen, image.Width / 2 + 1, 3, image.Width / 2 + 1, image.Height - 4); checkBoxGraphics.DrawLine(expandLineShadowPen, image.Width / 2 - 1, 3, image.Width / 2 - 1, image.Height - 4); } // Plus checkBoxGraphics.DrawLine(expandLinePen, 3, image.Height / 2, image.Width - 4, image.Height / 2); if (state == ExpandBoxState.ExpandDisabled || state == ExpandBoxState.ExpandHot || state == ExpandBoxState.ExpandNormal || state == ExpandBoxState.ExpandPressed) { checkBoxGraphics.DrawLine(expandLinePen, image.Width / 2, 3, image.Width / 2, image.Height - 4); } } expandBoxImages[state] = image; }
private void InitExpandBox(ExpandBoxState state) { if (expandBoxImages != null && expandBoxImages.ContainsKey(state)) { return; } if (expandBoxImages == null) { expandBoxImages = new Dictionary <ExpandBoxState, Bitmap>(); } Bitmap image = new Bitmap(CheckBoxSize.Width, CheckBoxSize.Height); using (Graphics checkBoxGraphics = Graphics.FromImage(image)) { Color plusSignColor; Pen expandLineShadowPen; Pen expandLinePen; if (state == ExpandBoxState.ExpandNormal || state == ExpandBoxState.CollapseNormal) { plusSignColor = Color.FromArgb(24, 32, 82); expandLinePen = new Pen(Color.FromArgb(255, plusSignColor)); expandLineShadowPen = new Pen(Color.FromArgb(64, plusSignColor)); CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); } else if (state == ExpandBoxState.ExpandHot || state == ExpandBoxState.CollapseHot) { plusSignColor = Color.FromArgb(32, 48, 123); expandLinePen = new Pen(Color.FromArgb(255, plusSignColor)); expandLineShadowPen = new Pen(Color.FromArgb(64, plusSignColor)); CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedHot); } else if (state == ExpandBoxState.ExpandPressed || state == ExpandBoxState.CollapsePressed) { plusSignColor = Color.FromArgb(48, 64, 164); expandLinePen = new Pen(Color.FromArgb(255, plusSignColor)); expandLineShadowPen = new Pen(Color.FromArgb(96, plusSignColor)); CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedPressed); } else { plusSignColor = Color.FromArgb(24, 28, 41); expandLinePen = new Pen(Color.FromArgb(128, plusSignColor)); expandLineShadowPen = new Pen(Color.FromArgb(32, plusSignColor)); CheckBoxRenderer.DrawCheckBox(checkBoxGraphics, Point.Empty, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedDisabled); } // Plus Shadow checkBoxGraphics.DrawLine(expandLineShadowPen, 3, image.Height / 2 + 1, image.Width - 4, image.Height / 2 + 1); checkBoxGraphics.DrawLine(expandLineShadowPen, 3, image.Height / 2 - 1, image.Width - 4, image.Height / 2 - 1); if (state == ExpandBoxState.ExpandDisabled || state == ExpandBoxState.ExpandHot || state == ExpandBoxState.ExpandNormal || state == ExpandBoxState.ExpandPressed) { checkBoxGraphics.DrawLine(expandLineShadowPen, image.Width / 2 + 1, 3, image.Width / 2 + 1, image.Height - 4); checkBoxGraphics.DrawLine(expandLineShadowPen, image.Width / 2 - 1, 3, image.Width / 2 - 1, image.Height - 4); } // Plus checkBoxGraphics.DrawLine(expandLinePen, 3, image.Height / 2, image.Width - 4, image.Height / 2); if (state == ExpandBoxState.ExpandDisabled || state == ExpandBoxState.ExpandHot || state == ExpandBoxState.ExpandNormal || state == ExpandBoxState.ExpandPressed) { checkBoxGraphics.DrawLine(expandLinePen, image.Width / 2, 3, image.Width / 2, image.Height - 4); } } expandBoxImages[state] = image; }
public void DrawExpandBox(Graphics g, Point loc, ExpandBoxState state) { InitExpandBox(state); g.DrawImageUnscaled(expandBoxImages[state], loc); }