一.引子
VS中没有了VB中的线条控件,虽然我没有用过VB,不过却看到过这个控件在VB环境下的效果.在一些情况下,或许我们还真的要用到这样的控件,那么索性就自己写了一个.
二.设计时效果


三.运行时效果

四.简单谈谈实现思路
因为实现的比较简单,所以只是通过设置一个角度的属性来调整整个线条的倾斜角度,同时使用一个路径来记录这个线条的4个端点,最后将控件的Region属性设置为该路径决定的Region.就这么简单.呵呵.
五.部分源代码
private
int
_lineWidth
=
10
;
//
线宽
private
float
_angle
=
0
;
//
角度
private
int
_lineLength ;
private
Color _lineColor
=
Color.Black;

/**/
/// <summary>
/// 线宽
/// </summary>
[Category(
"
Jcs属性
"
),Description(
"
线宽
"
)]
public
int
LineWidth

...
{

get ...{ return _lineWidth; }
set

...{
_lineWidth = value;
this.Invalidate();
RefreshSize();
}
}
[Category(
"
Jcs属性
"
), Description(
"
线长
"
)]
public
int
LineLength

...
{

get ...{ return _lineLength; }
set

...{
_lineLength = value;
this.Invalidate();
RefreshSize();
}
}
[Category(
"
Jcs属性
"
), Description(
"
角度,注意:以角度计算。
"
)]
public
float
LineAngle

...
{

get ...{ return _angle; }
set

...{
if (value > 360 || value < 0)
throw new Exception("输入的角度范围越界。");
this._angle = value;
this.Invalidate();
RefreshSize();
}
}
[Category(
"
Jcs属性
"
), Description(
"
线条颜色。
"
)]
public
Color LineColor

...
{

get ...{ return _lineColor; }
set

...{
_lineColor = value;
this.Invalidate();
}
}