protected override void OnPaint(PaintEventArgs e) { int y = Style == Styles.Underlined ? -UnderlineSize + 1 : 0; Graphics G = e.Graphics; G.SmoothingMode = SmoothingMode.HighQuality; G.Clear(Parent.BackColor); using (SolidBrush brush = new SolidBrush(BackColor)) { if (Style == Styles.Outlined) { G.FillPath(brush, GlobalHelpers.GetRoundedRect(new Rectangle(0, 0, Width - 1, Height - 1), 5)); using (Pen outlinePen = new Pen(EffectColor)) { G.DrawPath(outlinePen, GlobalHelpers.GetRoundedRect(new Rectangle(0, 0, Width - 1, Height - 1), 5)); } } else if (Style == Styles.Underlined) { using (SolidBrush darkBrush = new SolidBrush(EffectColor)) { G.FillPath(darkBrush, GlobalHelpers.GetRoundedRect(new Rectangle(-1, -1, Width + 1, Height + 1), 5)); } G.SetClip(new Rectangle(0, 0, Width, Height - UnderlineSize)); G.FillPath(brush, GlobalHelpers.GetRoundedRect(new Rectangle(-1, -1, Width + 1, Height - UnderlineSize + 1), 5)); } else { G.FillPath(brush, GlobalHelpers.GetRoundedRect(new Rectangle(-1, -1, Width + 1, Height + 1), 5)); } } if (!string.IsNullOrEmpty(Text)) { using (SolidBrush textBrush = new SolidBrush(ForeColor)) { if (TextAlignment == TextAlign.Center) { G.DrawString(Text, Font, textBrush, (Width - G.MeasureString(Text, Font).Width) / 2, (Height - G.MeasureString(Text, Font).Height) / 2 + y); } if (TextAlignment == TextAlign.Left) { G.DrawString(Text, Font, textBrush, 4, (Height - G.MeasureString(Text, Font).Height) / 2 + y); } } } base.OnPaint(e); }
private void DrawImage(Graphics G) { #region "Background Image" if (BackgroundImage != null) { SizeF destinationSize = CalculateImageSize(BackgroundImage); #region "Image Container" if (ImageContainer) { G.SetClip(CalculateContainerPosition(destinationSize)); using (SolidBrush brush = new SolidBrush(ImageContainerColor)) { G.FillPath(brush, GlobalHelpers.GetRoundedRect(new RectangleF(-1, -1, Width + 1, Height + 1), 5)); } G.ResetClip(); } #endregion #region "Draw Image" if (_cachedTransparentImage != null) { if (BackgroundImageLayout == Iconlayout.Scaled) { G.DrawImage(_cachedTransparentImage, new RectangleF( Width - destinationSize.Width - 5, (Height - destinationSize.Height) / 2, destinationSize.Width, destinationSize.Height)); } else { G.DrawImage(_cachedTransparentImage, Width - BackgroundImage.Width - 5, (Height - BackgroundImage.Height) / 2); } } #endregion } #endregion }
protected override void OnPaint(PaintEventArgs e) { Graphics G = e.Graphics; G.SmoothingMode = SmoothingMode.HighQuality; G.Clear(BackColor); using (SolidBrush brush = new SolidBrush(BackColor)) { G.FillPath(brush, GlobalHelpers.GetRoundedRect(new Rectangle(0, 0, Width - 1, Height - 1), 4)); } using (Pen pen = new Pen(Color.Gray)) { G.DrawPath(pen, GlobalHelpers.GetRoundedRect(new Rectangle(0, 0, Width - 1, Height - 1), 4)); } }
private void DrawUnderline(Graphics G, SizeF imageSizeF) { using ( SolidBrush underlineBrush = new SolidBrush(UnderlineColor), backColorBrush = new SolidBrush(BackColor)) { if (Underline != UnderlineStyle.None) { Rectangle clipping = new Rectangle(0, Height - UnderlineSize, Width, UnderlineSize); if (BackgroundImage != null) { Rectangle imageContainerPosition = CalculateContainerPosition(imageSizeF); switch (Underline) { case UnderlineStyle.ImageOnly: if (BackgroundImage != null) { clipping = new Rectangle(imageContainerPosition.X, Height - UnderlineSize, imageContainerPosition.Width, UnderlineSize); } break; case UnderlineStyle.ExcludeImage: if (BackgroundImage != null) { clipping = new Rectangle(0, Height - UnderlineSize, Width - imageContainerPosition.Width + 5, UnderlineSize); } break; } } G.SetClip(clipping); G.FillPath(underlineBrush, GlobalHelpers.GetRoundedRect(new Rectangle(-1, -1, Width + 1, Height + 1), 5)); G.ResetClip(); //DrawImage(G); //G.FillPath(underlineBrush, // GlobalHelpers.GetRoundedRect(new Rectangle(-1, -1, Width + 1, Height + 1), 5)); //G.SetClip(new Rectangle(-1, -1, Width + 1, Height - UnderlineSize)); //G.FillPath(backColorBrush, // GlobalHelpers.GetRoundedRect(new Rectangle(-1, -1, Width + 1, Height - UnderlineSize), 5)); //DrawImage(G); //G.ResetClip(); } } }
protected override void OnPaint(PaintEventArgs e) { Graphics G = e.Graphics; G.Clear(Parent.BackColor); G.SmoothingMode = SmoothingMode.HighQuality; using ( SolidBrush backColorBrush = new SolidBrush(BackColor), foreColorBrush = new SolidBrush(ForeColor), titleColorBrush = new SolidBrush(Color.FromArgb(180, ForeColor))) { G.FillPath(backColorBrush, GlobalHelpers.GetRoundedRect(new Rectangle(-1, -1, Width + 1, Height + 1), 5)); DrawImage(G); if (BackgroundImage != null) { DrawUnderline(G, CalculateImageSize(BackgroundImage)); } else { DrawUnderline(G, new SizeF()); } if (!string.IsNullOrEmpty(Title)) { G.DrawString(Title.ToUpper(), new Font("Verdana", 8), titleColorBrush, 12, (Height - G.MeasureString(Text, Font).Height) / 2 - 7); } G.DrawString(Text, Font, foreColorBrush, 12, (Height - G.MeasureString(Text, Font).Height) / 2 + (string.IsNullOrEmpty(Title) ? 0 : 8)); } if (!Enabled) { using (SolidBrush disabledBrush = new SolidBrush(Color.FromArgb(100, 222, 222, 222))) { G.FillPath(disabledBrush, GlobalHelpers.GetRoundedRect(new Rectangle(-1, -1, Width + 1, Height + 1), 4)); } } base.OnPaint(e); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics G = e.Graphics; G.SmoothingMode = SmoothingMode.HighQuality; G.Clear(Parent.BackColor); using (SolidBrush backBrush = new SolidBrush(Color.FromArgb(5, 30, 30, 30))) { G.FillPath(backBrush, GlobalHelpers.GetRoundedRect(new Rectangle(0, 0, 13, 13), 3)); } G.SetClip(new Rectangle(3, 3, 8, 8)); if (Checked) { using (SolidBrush backColorBrush = new SolidBrush(BackColor)) { G.FillPath(backColorBrush, GlobalHelpers.GetRoundedRect(new RectangleF(2, 2, 9, 9), 4.3F)); } } G.ResetClip(); using (Pen pen = new Pen(Color.FromArgb(85, 13, 13, 13))) { G.DrawPath(pen, GlobalHelpers.GetRoundedRect(new Rectangle(0, 0, 13, 13), 2)); } using (SolidBrush foreColorBrush = new SolidBrush(ForeColor)) { G.DrawString(Text, Font, foreColorBrush, 15, (Height - G.MeasureString(Text, Font).Height) / 2); } if (Enabled == false) { using (SolidBrush disabledBrush = new SolidBrush(Color.FromArgb(100, 222, 222, 222))) { G.FillPath(disabledBrush, GlobalHelpers.GetRoundedRect(new Rectangle(0, 0, 13, 13), 3)); G.DrawString(Text, Font, disabledBrush, 15, (Height - G.MeasureString(Text, Font).Height) / 2); } } }
protected override void OnPaint(PaintEventArgs pevent) { Graphics G = pevent.Graphics; G.Clear(Parent.BackColor); G.SmoothingMode = SmoothingMode.HighQuality; G.InterpolationMode = InterpolationMode.HighQualityBicubic; using (SolidBrush backColorBrush = new SolidBrush(BackColor)) { G.FillPath(backColorBrush, GlobalHelpers.GetRoundedRect(new RectangleF(-1, -1, Width + 1, Height + 1), 5)); } using (SolidBrush overlapBrush = new SolidBrush(_overlapColor)) { G.FillPath(overlapBrush, GlobalHelpers.GetRoundedRect(new RectangleF(-1, -1, Width + 1, Height + 1), 5)); } using (SolidBrush textBrush = new SolidBrush(ForeColor)) { PointF textPosition = new PointF((Width - G.MeasureString(Text, Font).Width) / 2, (Height - G.MeasureString(Text, Font).Height) / 2); if (ImageList != null) { int index = ImageIndex; if (!string.IsNullOrEmpty(ImageKey) && index != -1) { index = ImageList.Images.IndexOfKey(ImageKey); } if (index != -1) { ImageList.Draw(G, Convert.ToInt32(textPosition.X) - ImageList.ImageSize.Width - 5, (Height - ImageList.ImageSize.Height) / 2, ImageIndex); } } else if (Image != null) { G.DrawImage(Image, new Point(Convert.ToInt32(textPosition.X) - Image.Width - 5, (Height - Image.Height) / 2)); } G.DrawString(Text, Font, textBrush, textPosition); } if (Underline) { using (SolidBrush underlineBrush = new SolidBrush(UnderlineColor)) { G.SetClip(new Rectangle(0, Height - UnderlineSize, Width, UnderlineSize)); G.FillPath(underlineBrush, GlobalHelpers.GetRoundedRect(new RectangleF(-1, -1, Width + 1, Height + 1), 5)); } } if (Enabled == false) { using (SolidBrush disabledBrush = new SolidBrush(Color.FromArgb(100, 222, 222, 222))) { G.FillPath(disabledBrush, GlobalHelpers.GetRoundedRect(new RectangleF(-1, -1, Width + 1, Height + 1), 5)); } } }
private Image EditBackgroundImage(Image value) { return(GlobalHelpers.TuneTransparency(value, ImageTransparency, AntiAliasImage)); }
protected override void OnPaint(PaintEventArgs e) { Graphics G = e.Graphics; //Get the region of the colored part float percent = (float)Width / Maximum * Value; //Transparent background effect G.Clear(Parent.BackColor); G.SmoothingMode = SmoothingMode.HighQuality; //Set clipping to reduce anti aliasing G.SetClip(new RectangleF(0, 0, Width, Height)); //Create the background brush using (SolidBrush inactiveBackColorBrush = new SolidBrush(InactiveBackColor)) //Draw the background { G.FillPath(inactiveBackColorBrush, GlobalHelpers.GetRoundedRect(new RectangleF(-1, -1, Width + 1, Height + 1), CornerRounding)); G.SetClip(new Rectangle(0, 0, Convert.ToInt32(percent), Height)); using (SolidBrush backColorBrush = new SolidBrush(BackColor)) { G.FillPath(backColorBrush, GlobalHelpers.GetRoundedRect(new RectangleF(-1, -1, percent + 1, Height + 1), CornerRounding)); } if (Underline) { using (SolidBrush underlineBrush = new SolidBrush(UnderlineColor)) { G.SetClip(new Rectangle(0, Height - UnderlineSize, Convert.ToInt32(percent), UnderlineSize)); G.FillPath(underlineBrush, GlobalHelpers.GetRoundedRect(new RectangleF(-1, -1, percent + 1, Height + 1), CornerRounding)); } } } using (SolidBrush foreColorBrush = new SolidBrush(ForeColor)) using (SolidBrush alternateForeColorBrush = new SolidBrush(AlternateForeColor)) { G.SetClip(new Rectangle(0, 0, Convert.ToInt32(percent), Height)); G.DrawString(Text, Font, foreColorBrush, 5, (Height - G.MeasureString(Text, Font).Height) / 2); G.SetClip(new Rectangle(Convert.ToInt32(percent), 0, Width, Height)); G.DrawString(Text, Font, alternateForeColorBrush, 5, (Height - G.MeasureString(Text, Font).Height) / 2); } if (!Enabled) { using (SolidBrush disabledBrush = new SolidBrush(Color.FromArgb(100, 222, 222, 222))) { G.FillPath(disabledBrush, GlobalHelpers.GetRoundedRect(new RectangleF(-1, -1, Width + 1, Height + 1), CornerRounding)); } } G.ResetClip(); base.OnPaint(e); }