【Asp.net精品源码栏目提醒】:网学会员,鉴于大家对Asp.net精品源码十分关注,论文会员在此为大家搜集整理了“C#自定义控件五报警按钮 - 其它资料”一文,供大家参考学习!
C自定义控件五报警按钮效果图:这个是本人最得意的控件之一,在商业项目中使用,史无前例,个人原创,应用于项目EcanAlarmSystem 报警监控系统中,作为报警组件中的核心组件,在速度和展现形式上完美符合现实需求。
分析:一个防区有六种状态,分别是布防、撤防、旁路、报警、故障、断开,需要在不同状态显示不同的颜色,一个防区对应的属性有防区号、防区名、防区图片、防区类型、主机类型、子系统、地图 X 坐标、地图 Y 坐标。
第一步:添加用户控件,命名为 myAlarmButton第二步:定义枚举public enum myButtonState bufang 1//布防状态 chefang 2//撤防状态 panglu 3//旁路状态 baojing 4//报警状态 duankai 5//防区断开 guzhang 6//防区故障 第三步:定义属性第四步:重写 OnPaint 方法protected override void OnPaintPaintEventArgs e this.Size new Size30 30 Graphics g e.Graphics g.FillEllipsenew SolidBrushthis.nowColor 0.0f 0.0f 30 30 g.DrawEllipsenew PenColor.Black 1 0.0f 0.0f 29 29 g.DrawStringdefenceID new Font 宋 体 9 FontStyle.BoldBrushes.White 3 9 第五步:通过状态属性改变来改变颜色/// /// 防区当前状态 /// CategoryAttribute报警按钮信息 Description防区当前状态 public myButtonState DefenceState set defenceState value if value myButtonState.bufang myTimer.Stop isRedColor false this.nowColor this.bufangColor else if value myButtonState.chefang myTimer.Stop isRedColor false this.nowColor this.chefangColor else if value myButtonState.panglu myTimer.Stop isRedColor false this.nowColor this.pangluColor else if value myButtonState.duankai myTimer.Stop isRedColor false this.nowColor this.duankaiColor else if value myButtonState.guzhang myTimer.Stop isRedColor false this.nowColor this.guzhangColor else if value myButtonState.baojing myTimer.Start this.Invalidate get return defenceState 贴出全部代码://控件名:myAlarmButton//作者:刘典武//时间:2011-06-09using Systemusing System.Collections.Genericusing System.ComponentModelusing System.Drawingusing System.Datausing System.Textusing System.Windows.Formsnamespace myControl public enum myButtonState bufang 1//布防状态 chefang 2//撤防状态 panglu 3//旁路状态 baojing 4//报警状态 duankai 5//防区断开 guzhang 6//防区故障 public partial class myAlarmButton : UserControl public myAlarmButton InitializeComponent myTimer new Timer myTimer.Interval myInterval myTimer.Tick new EventHandlermyTimer_Tick //设置Style支持透明背景色 this.SetStyleControlStyles.OptimizedDoubleBuffer ControlStyles.ResizeRedraw ControlStyles.Selectable ControlStyles.AllPaintingInWmPaint ControlStyles.UserPaint ControlStyles.SupportsTransparentBackColor true this.BackColor Color.Transparent private string defenceID 010//防区号 private string defenceName 010//防区名称 private string defenceType 03//防区类型 private string imageName//防区对应图片名称 private string subSystem 01//防区所属子系统 private string hostType VISTA120//防区对应主机类型 private int x//防区在地图上的X坐标 private int y//防区在地图上的Y坐标 private int myInterval 300//报警颜色更改时间隔 private bool isRedColor false//当前是否红色显示 private Timer myTimer private myButtonState defenceState myButtonState.chefang//防区当前状态 private Color bufangColor Color.YellowGreen//布防颜色