笔颜色和宽度的DefaultValue

时间:2016-07-26 10:12:03

标签: c# winforms border rectangles graphic

我想绘制一个矩形形状和文本。我的用户控件中有一个边框粗细和边框画笔属性。但是我得到一个没有边框的矩形。
我的代码:

float borderThickness;
[Description(""), Category("Appearance"), DefaultValue(1.0)]
public float BorderThickness 
{
  get {
        return borderThickness;
  }
  set {
        borderThickness = value; 
        Invalidate();
      }
}

//it is hex value.
Color borderBrush;
[Description(""), Category("Appearance"), DefaultValue("FF0000")]
public Color BorderBrush {
   get {
         return borderBrush;
   }
   set {
         borderBrush = value; 
         Invalidate();
   }
} 

绘画和绘画:

void DrawRect(Color br, float x, float y, float w, float h)
{
    g.DrawRectangle(br, x, y, w, h);
}

protected override void OnPaint(PaintEventArgs e)
{
    Graphics g = e.Graphics;
    Pen selPen = new Pen(this.BorderBrush,this.BorderThickness);
    this.Text = Number;
    DrawRect(selPen,this.ClientRectangle);
}

0 个答案:

没有答案