• λ我爱Aspx >> C#.Net >> 为你的CheckBox和RadioButton控件添色加彩
  • 为你的CheckBox和RadioButton控件添色加彩

  • :aspxer  Դ:internet  :2007-5-12 7:45:06  ؼ:
  • 通过扩展现有的CheckBox和RadioButton控件,可以把这些控件的外观改变不同的颜色,下面就是一个简单的例子。

    首先建立ColorCheckControl工程,添加两个控件类:

    ColoredCheckBox.cs

    using System; using System.Windows.Forms; using System.Drawing; using System.ComponentModel; namespace ColorCheckControl &#123; /// <summary> /// ColoredCheckBox 的摘要说明。 /// </summary> public class ColoredCheckBox : CheckBox &#123; //添加自定义颜色属性 private Color checkColor; public Color checkBGColor; public ColoredCheckBox() &#123; this.checkColor = this.ForeColor; this.Paint += new PaintEventHandler(this.PaintHandler); &#125; [Description("checkColor由于显示在CheckBox选中时的颜色")] public Color CheckColor &#123; get &#123; return checkColor; &#125; set &#123; checkColor = value; this.Invalidate(); &#125; &#125; public Color checkBgColor &#123; get &#123; return checkBGColor; &#125; set &#123; checkBGColor = value; &#125; &#125; private void PaintHandler (object sender, PaintEventArgs pe) &#123; Point pt = new Point(); if (this.CheckAlign == ContentAlignment.BottomCenter) &#123; pt.X = (this.Width / 2) - 4; pt.Y = this.Height - 11; &#125; if (this.CheckAlign == ContentAlignment.BottomLeft) &#123; pt.X = 3; pt.Y = this.Height - 11; &#125; if (this.CheckAlign == ContentAlignment.BottomRight) &#123; pt.X = this.Width - 11; pt.Y = this.Height - 11; &#125; if (this.CheckAlign == ContentAlignment.MiddleCenter) &#123; pt.X = (this.Width / 2) - 4; pt.Y = (this.Height / 2) - 4; &#125; if (this.CheckAlign == ContentAlignment.MiddleLeft) &#123; pt.X = 3; pt.Y = (this.Height / 2) - 4; &#125; if (this.CheckAlign == ContentAlignment.MiddleRight) &#123; pt.X = this.Width - 11; pt.Y = (this.Height / 2) - 4; &#125; if (this.CheckAlign == ContentAlignment.TopCenter) &#123; pt.X = (this.Width / 2) - 4; pt.Y = 3; &#125; if (this.CheckAlign == ContentAlignment.TopLeft) &#123; pt.X = 3; pt.Y = 3; &#125; if (this.CheckAlign == ContentAlignment.TopRight) &#123; pt.X = this.Width - 11; pt.Y = 3; &#125; DrawBackColor(pe.Graphics,this.checkBGColor,pt); if (this.Checked) DrawCheck(pe.Graphics,this.checkColor,pt); &#125; public void DrawCheck(Graphics g, Color c, Point pt) &#123; Pen pen = new Pen(this.checkColor); g.DrawLine(pen, pt.X, pt.Y + 2, pt.X + 2, pt.Y + 4); g.DrawLine(pen, pt.X, pt.Y + 3, pt.X + 2, pt.Y + 5); g.DrawLine(pen, pt.X, pt.Y + 4, pt.X + 2, pt.Y + 6); g.DrawLine(pen, pt.X + 3, pt.Y + 3, pt.X + 6, pt.Y); g.DrawLine(pen, pt.X + 3, pt.Y + 4, pt.X + 6, pt.Y + 1); g.DrawLine(pen, pt.X + 3, pt.Y + 5, pt.X + 6, pt.Y + 2); &#125; public void DrawBackColor(Graphics g,Color b, Point pt) &#123; SolidBrush br = new SolidBrush(this.checkBgColor); g.FillRectangle(br,pt.X,pt.Y,7,7); &#125; &#125; &#125;

    Ҷƪл˵?
  • һƪC#中读取数据库中Image数据
    һƪC#编程入门三部曲:第一步 创建一个表单