/// <summary> /// 画水印效果 /// </summary> /// <param name="g"></param> protected void DrawString(Graphics g) { if (_ZEmptyTextTip != "" && string.IsNullOrEmpty(this.Text) && !Focused) { Font fon = new Font("宋体", 9); TextRenderer.DrawText( g, _ZEmptyTextTip, Font, base.ClientRectangle, Color.DarkGray, TextFormat.GetTextFormatFlags(ContentAlignment.MiddleLeft, false)); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); base.OnPaintBackground(e); Graphics g = e.Graphics; Rectangle radioButtonrect; Rectangle textRect; CalculateRect(out radioButtonrect, out textRect); g.SmoothingMode = SmoothingMode.AntiAlias; Color borderColor; Color innerBorderColor; Color checkColor; bool hover = false; if (Enabled) { switch (ControlState) { case ControlState.Hover: borderColor = _BorderColor; innerBorderColor = _BorderColor; checkColor = ColorClass.GetColor(_BorderColor, 0, 35, 24, 9); hover = true; break; case ControlState.Pressed: borderColor = _BorderColor; innerBorderColor = ColorClass.GetColor(_BorderColor, 0, -13, -8, -3); checkColor = ColorClass.GetColor(_BorderColor, 0, -35, -24, -9); hover = true; break; default: borderColor = _BorderColor; innerBorderColor = Color.Empty; checkColor = _BorderColor; break; } } else { borderColor = SystemColors.ControlDark; innerBorderColor = SystemColors.ControlDark; checkColor = SystemColors.ControlDark; } using (SolidBrush brush = new SolidBrush(Color.White)) { g.FillEllipse(brush, radioButtonrect); } if (hover) { using (Pen pen = new Pen(innerBorderColor, 2F)) { g.DrawEllipse(pen, radioButtonrect); } } if (Checked) { radioButtonrect.Inflate(-2, -2); using (GraphicsPath path = new GraphicsPath()) { path.AddEllipse(radioButtonrect); using (PathGradientBrush brush = new PathGradientBrush(path)) { brush.CenterColor = checkColor; brush.SurroundColors = new Color[] { Color.White }; Blend blend = new Blend(); blend.Positions = new float[] { 0f, 0.4f, 1f }; blend.Factors = new float[] { 0f, 0.4f, 1f }; brush.Blend = blend; g.FillEllipse(brush, radioButtonrect); } } radioButtonrect.Inflate(2, 2); } using (Pen pen = new Pen(borderColor)) { g.DrawEllipse(pen, radioButtonrect); } Color textColor = Enabled ? ForeColor : SystemColors.GrayText; TextRenderer.DrawText( g, Text, Font, textRect, textColor, TextFormat.GetTextFormatFlags(TextAlign, RightToLeft == RightToLeft.Yes)); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); base.OnPaintBackground(e); Rectangle rectangle; //图片范围 Rectangle rectangle2; //字体范围 this.CalculateRect(out rectangle, out rectangle2); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; if (base.Enabled) { //填充按钮颜色效果 GraphicsPath aa = GetGraphicPath.CreatePath(base.ClientRectangle, _JMRadius, RoundStyle.All, true); aa.CloseFigure(); //加载鼠标进入效果 if (SFVisibleEffect) { Color col1 = ColorClass.GetColor(_JMBaseColorTwo, 0, -20, -20, -20); Color col2 = ColorClass.GetColor(_JMBaseColor, 0, -20, -20, -20); GraphicsPath bb = GetGraphicPath.CreatePath(base.ClientRectangle, _JMRadius, RoundStyle.All, true); bb.CloseFigure(); g.FillPath(new LinearGradientBrush(base.ClientRectangle, col1, col2, LinearGradientMode.Vertical), bb); g.DrawPath(new Pen(new SolidBrush(Color.DarkGray)), aa); } else if (SFDownEffect)//加载鼠标按下效果 || Focused { Color col1 = ColorClass.GetColor(_JMBaseColorTwo, 0, -35, -35, -35); Color col2 = ColorClass.GetColor(_JMBaseColor, 0, -35, -35, -35); GraphicsPath cc = GetGraphicPath.CreatePath(base.ClientRectangle, _JMRadius, RoundStyle.All, true); cc.CloseFigure(); g.FillPath(new LinearGradientBrush(base.ClientRectangle, col1, col2, LinearGradientMode.Vertical), cc); g.DrawPath(new Pen(new SolidBrush(Color.DarkGray)), aa); } else { g.FillPath(new LinearGradientBrush(base.ClientRectangle, _JMBaseColorTwo, _JMBaseColor, LinearGradientMode.Vertical), aa); g.DrawPath(new Pen(new SolidBrush(Color.DarkGray)), aa); } //加载图片 if (base.Image != null) { g.InterpolationMode = InterpolationMode.HighQualityBilinear; g.DrawImage(base.Image, rectangle); } } else//不可用为“灰色” { //填充按钮颜色效果 GraphicsPath aa = GetGraphicPath.CreatePath(base.ClientRectangle, _JMRadius, RoundStyle.All, true); aa.CloseFigure(); g.FillPath(new LinearGradientBrush(base.ClientRectangle, SystemColors.ControlDark, SystemColors.ControlDark, LinearGradientMode.Vertical), aa); g.DrawPath(new Pen(new SolidBrush(Color.DarkGray)), aa); } //加载文字 TextRenderer.DrawText(g, this.Text, this.Font, rectangle2, this.ForeColor, TextFormat.GetTextFormatFlags(this.TextAlign, this.RightToLeft == RightToLeft.Yes)); if (_JMSFNew) { e.Graphics.DrawImage(Properties.Resources._new, new Rectangle(Width - 12, Height / 2 - 5, 10, 10)); } }