protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; if (Parent != null) { g.FillRectangle(new SolidBrush(Parent.BackColor), ClientRectangle); } g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - BorderThickness, ClientRectangle.Height - BorderThickness); g.FillPath(new SolidBrush(Color.White), ExtendedForms.RoundedRect(rect, BorderRadius)); Rectangle buttonRect = new Rectangle(ClientRectangle.Width - Height, ClientRectangle.Y, Height - 1, Height - 1); if (!Error) { if (_isSelected) { g.DrawPath(new Pen(BorderHoverColor, BorderThickness), ExtendedForms.RoundedRect(rect, BorderRadius)); g.DrawLine(new Pen(BorderHoverColor, BorderThickness), ClientRectangle.Width - Height, ClientRectangle.Y, ClientRectangle.Width - Height, ClientRectangle.Height); g.FillPath(new SolidBrush(ButtonSelectedColor), ExtendedForms.RoundedRightRect(buttonRect, BorderRadius)); } else { g.DrawPath(new Pen(BorderColor, BorderThickness), ExtendedForms.RoundedRect(rect, BorderRadius)); g.DrawLine(new Pen(BorderColor, BorderThickness), ClientRectangle.Width - Height, ClientRectangle.Y, ClientRectangle.Width - Height, ClientRectangle.Height); g.FillPath(new SolidBrush(ButtonColor), ExtendedForms.RoundedRightRect(buttonRect, BorderRadius)); } } else { g.DrawPath(new Pen(BorderErrorColor, BorderThickness), ExtendedForms.RoundedRect(rect, BorderRadius)); g.DrawLine(new Pen(BorderErrorColor, BorderThickness), ClientRectangle.Width - Height, ClientRectangle.Y, ClientRectangle.Width - Height, ClientRectangle.Height); } g.DrawLine(new Pen(ForeColor, 2), buttonRect.X + buttonRect.Width / 2 - 4, buttonRect.Height / 2 - 2, buttonRect.X + buttonRect.Width / 2, buttonRect.Height / 2 + 2); g.DrawLine(new Pen(ForeColor, 2), buttonRect.X + buttonRect.Width / 2 + 4, buttonRect.Height / 2 - 2, buttonRect.X + buttonRect.Width / 2, buttonRect.Height / 2 + 2); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; switch (CaptionTextAlignment) { case HorizontalAlignment.Center: sf.Alignment = StringAlignment.Center; break; case HorizontalAlignment.Left: sf.Alignment = StringAlignment.Near; break; case HorizontalAlignment.Right: sf.Alignment = StringAlignment.Far; break; } StateStyle style = NormalStyle; if (!Error) { if (_isSelected) { style = HoverStyle; } } else { style = ErrorStyle; } if (!Enabled) { style = DisabledStyle; } if (Parent != null) { g.FillRectangle(new SolidBrush(Parent.BackColor), ClientRectangle); } g.SmoothingMode = SmoothingMode.HighQuality; Rectangle textRect = new Rectangle( ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - BorderThickness, ClientRectangle.Height - BorderThickness); Rectangle captionRect = new Rectangle(); GraphicsPath textPath = ExtendedForms.RoundedRect(textRect, BorderRadius); GraphicsPath captionPath = null; if (_captionSize.Width > 0) { switch (CaptionPosition) { case ContentPosition.Left: captionRect = new Rectangle( ClientRectangle.X, ClientRectangle.Y, _captionSize.Width + 2 * BorderPadding, Height - BorderThickness); textRect = new Rectangle( captionRect.Width, ClientRectangle.Y, ClientRectangle.Width - BorderThickness - captionRect.Width, ClientRectangle.Height - BorderThickness); if (CaptionShowBorder) { textPath = ExtendedForms.RoundedRightRect(textRect, BorderRadius); captionPath = ExtendedForms.RoundedLeftRect(captionRect, BorderRadius); } else { textPath = ExtendedForms.RoundedRect(textRect, BorderRadius); } break; case ContentPosition.Right: captionRect = new Rectangle( ClientRectangle.Right - (_captionSize.Width + 2 * BorderPadding) - BorderThickness, ClientRectangle.Y, _captionSize.Width + 2 * BorderPadding, Height - BorderThickness); textRect = new Rectangle( ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - BorderThickness - captionRect.Width, ClientRectangle.Height - BorderThickness); if (CaptionShowBorder) { textPath = ExtendedForms.RoundedLeftRect(textRect, BorderRadius); captionPath = ExtendedForms.RoundedRightRect(captionRect, BorderRadius); } else { textPath = ExtendedForms.RoundedRect(textRect, BorderRadius); } break; case ContentPosition.Top: captionRect = new Rectangle( ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - BorderThickness, ClientRectangle.Y + _captionSize.Height + BorderPadding); textRect = new Rectangle( ClientRectangle.X, ClientRectangle.Y + captionRect.Height, ClientRectangle.Width - BorderThickness, ClientRectangle.Height - captionRect.Height - BorderThickness); if (CaptionShowBorder) { textPath = ExtendedForms.RoundedBottomRect(textRect, BorderRadius); captionPath = ExtendedForms.RoundedTopRect(captionRect, BorderRadius); } else { textPath = ExtendedForms.RoundedRect(textRect, BorderRadius); } break; case ContentPosition.Bottom: captionRect = new Rectangle( ClientRectangle.X, ClientRectangle.Height - (_captionSize.Height + BorderPadding) - 1, ClientRectangle.Width - BorderThickness, _captionSize.Height + BorderPadding); textRect = new Rectangle( ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - BorderThickness, ClientRectangle.Height - captionRect.Height - BorderThickness); if (CaptionShowBorder) { textPath = ExtendedForms.RoundedTopRect(textRect, BorderRadius); captionPath = ExtendedForms.RoundedBottomRect(captionRect, BorderRadius); } else { textPath = ExtendedForms.RoundedRect(textRect, BorderRadius); } break; } } g.FillPath(new SolidBrush(style.BackColor), textPath); if (_captionSize.Width > 0 && captionPath != null && CaptionShowBorder) { if (CaptionFlatStyle) { g.FillPath(new SolidBrush(CaptionNormalStyle.BackColor), captionPath); } else { g.FillPath(new LinearGradientBrush(captionRect, CaptionNormalStyle.BackColor.Lighten(20), CaptionNormalStyle.BackColor, 90), captionPath); switch (CaptionPosition) { case ContentPosition.Left: g.DrawLine(new Pen(CaptionNormalStyle.BackColor.Lighten(40)), captionRect.X + BorderRadius, captionRect.Top + 1, captionRect.Right, captionRect.Top + 1); break; case ContentPosition.Right: g.DrawLine(new Pen(CaptionNormalStyle.BackColor.Lighten(40)), captionRect.X, captionRect.Top + 1, captionRect.Right - BorderRadius, captionRect.Top + 1); break; } } } if (_captionSize.Width > 0 && captionPath != null) { g.DrawPath(new Pen(style.BorderColor, BorderThickness), captionPath); } g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; Rectangle captionTempRect = new Rectangle(captionRect.Location, captionRect.Size); if (CaptionPosition == ContentPosition.Left || CaptionPosition == ContentPosition.Right) { captionTempRect.Inflate(0, -BorderPadding / 2 - 2 * BorderThickness); } else { captionTempRect.Inflate(-BorderPadding / 2 - 2 * BorderThickness, 0); if (CaptionImage != null) { captionTempRect.Offset(CaptionImageSize.Width + BorderPadding - 1, 0); } } g.DrawString(Caption, this.Font, new SolidBrush(CaptionNormalStyle.ForeColor), captionTempRect, sf); if (CaptionImage != null) { int imageY = captionTempRect.Y + (captionTempRect.Bottom - captionTempRect.Y) / 2 - CaptionImageSize.Height / 2; g.DrawImage(CaptionImage, captionTempRect.X - (_captionSize.Height + BorderPadding), imageY, CaptionImageSize.Width, CaptionImageSize.Height); } if (_captionSize.Width > 0 && CaptionShowBorder) { switch (CaptionPosition) { case ContentPosition.Left: g.DrawLine(new Pen(style.BorderColor, BorderThickness), captionRect.Right, 0, captionRect.Right, Height); break; case ContentPosition.Right: g.DrawLine(new Pen(style.BorderColor, BorderThickness), captionRect.Left, 0, captionRect.Left, Height); break; } } g.DrawPath(new Pen(style.BorderColor, BorderThickness), textPath); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; if (Parent != null) { g.FillRectangle(new SolidBrush(Parent.BackColor), ClientRectangle); } StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; switch (TextAlign) { case ContentAlignment.BottomLeft: sf.Alignment = StringAlignment.Near; break; case ContentAlignment.MiddleLeft: sf.Alignment = StringAlignment.Near; break; case ContentAlignment.TopLeft: sf.Alignment = StringAlignment.Near; break; case ContentAlignment.BottomCenter: sf.Alignment = StringAlignment.Center; break; case ContentAlignment.MiddleCenter: sf.Alignment = StringAlignment.Center; break; case ContentAlignment.TopCenter: sf.Alignment = StringAlignment.Center; break; case ContentAlignment.BottomRight: sf.Alignment = StringAlignment.Far; break; case ContentAlignment.MiddleRight: sf.Alignment = StringAlignment.Far; break; case ContentAlignment.TopRight: sf.Alignment = StringAlignment.Far; break; } g.SmoothingMode = SmoothingMode.AntiAlias; int captionWidth = ( int )g.MeasureString(Caption, Font).Width + 2 * _spacing; Rectangle captionRect = new Rectangle(ClientRectangle.X, ClientRectangle.Y, captionWidth, ClientRectangle.Height - 1); Rectangle textRect = new Rectangle(ClientRectangle.X + captionWidth, ClientRectangle.Y, ClientRectangle.Width - 1 - captionWidth, ClientRectangle.Height - 1); if (CaptionFlatStyle) { g.FillPath(new SolidBrush(CaptionNormalStyle.BackColor), ExtendedForms.RoundedLeftRect(captionRect, BorderRadius)); } else { g.FillPath(new LinearGradientBrush(captionRect, CaptionNormalStyle.BackColor.Lighten(20), CaptionNormalStyle.BackColor, 90), ExtendedForms.RoundedLeftRect(captionRect, BorderRadius)); g.DrawLine(new Pen(CaptionNormalStyle.BackColor.Lighten(40)), captionRect.X + BorderRadius, captionRect.Top + 1, captionRect.Right, captionRect.Top + 1); } g.FillPath(new SolidBrush(BackColor), ExtendedForms.RoundedRightRect(textRect, BorderRadius)); g.DrawPath(new Pen(BorderColor), ExtendedForms.RoundedLeftRect(captionRect, BorderRadius)); g.DrawPath(new Pen(BorderColor), ExtendedForms.RoundedRightRect(textRect, BorderRadius)); Rectangle innerCaptionRect = captionRect; innerCaptionRect.Inflate(-1, -1); g.DrawPath(new Pen(CaptionNormalStyle.BackColor.Lighten(CaptionNormalStyle.InnerBorderPenLightenValue)), ExtendedForms.RoundedLeftRect(innerCaptionRect, BorderRadius)); g.SmoothingMode = SmoothingMode.HighSpeed; //captionRect.Offset( _spacing, 0 ); //textRect.Offset( _spacing, 0 ); //Rectangle captionRect = new Rectangle( ClientRectangle.Location, new Size( captionWidth, ClientRectangle.Size.Height ) ); g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; g.DrawString((_allCaps) ? Caption.ToUpper() : Caption, Font, new SolidBrush(CaptionNormalStyle.ForeColor), captionRect, sf); //Rectangle textRect = new Rectangle( new Point( captionWidth, ClientRectangle.Location.Y ), ClientRectangle.Size ); g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; g.DrawString((_allCaps) ? Text.ToUpper() : Text, Font, new SolidBrush(ForeColor), textRect, sf); }