在WINCE下,C#,硬件平台是触控机。
有个状态转换的地方想用指示灯来显示,就类似于组态软件中那种很真实的灯一样,状态一绿色,状态二红色。
VS2005中提供的控件里没有灯或者圆的控件。
如果能在绘图工具里画一个圆,在PS里加上点效果,然后利用这个为原型作为控件外形,再在C#里定义属性。
这样怎么实现。c#vs2005控件wince
有个状态转换的地方想用指示灯来显示,就类似于组态软件中那种很真实的灯一样,状态一绿色,状态二红色。
VS2005中提供的控件里没有灯或者圆的控件。
如果能在绘图工具里画一个圆,在PS里加上点效果,然后利用这个为原型作为控件外形,再在C#里定义属性。
这样怎么实现。c#vs2005控件wince
public bool Status
{
get{return _status;}
set{
_status = value;
this.BackgroundImage = _status ? _img1 : _img2;
}
public class BulbControl : Control
{
private BulbStatus status = BulbStatus.Off;
//自定义属性可在属性编辑窗口编辑
[Category("UserDefine Attributes")]
[Description("BulbControl used to indicate a state!")]
[Browsable(true)]
public BulbStatus Status
{
get { return status; }
set
{
if (value != status)
{
status = value;
Invalidate();
}
}
} public BulbControl()
{
SetStyle(
ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer |
ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw |
ControlStyles.UserPaint, true);
Width = Height = 30;
} protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
DrawLight(g);
base.OnPaint(e);
}
//画灯,用图片绘制效果更佳
private void DrawLight(Graphics g)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddEllipse(0, 0, Width, Height);
using (PathGradientBrush brush = new PathGradientBrush(path))
{
g.SmoothingMode = SmoothingMode.AntiAlias;
g.CompositingQuality = CompositingQuality.HighQuality;
brush.CenterColor = Color.White;
brush.CenterPoint = new PointF(Width >> 1, Height >> 1);
brush.SurroundColors = new Color[] { status == BulbStatus.Off ? Color.Red : Color.Green };
g.FillPath(brush, path);
}
Region = new Region(path);
}
}
}
//状态枚举
public enum BulbStatus
{
On,
Off
}效果: