using System;
using SystemCollectionsGeneric; using SystemComponentModel; using SystemData; using SystemDrawing; using SystemText; using SystemWindowsForms; namespace ClientControl { //定义委托 public delegate void NewsClickEventHandle(object senderNewsEventArg args); public partial class NewsStage : Control { //定义事件 public event NewsClickEventHandle NewsClicked; private Graphics g; private bool isMouseOn = false; public NewsStage() { InitializeComponent(); //事件触发这样少了事件注册我们在其他窗体中引用控件时只需要注册事件和编辑事件处理程序即可可以对比上一篇博客 thisClick += new EventHandler(NewsStage_Click); thisMouseMove += new MouseEventHandler(NewsStage_MouseMove); thisMouseLeave += new EventHandler(NewsStage_MouseLeave); } void NewsStage_MouseLeave(object sender EventArgs e) { isMouseOn = false; thisInvalidate(); } void NewsStage_MouseMove(object sender MouseEventArgs e) { isMouseOn = true; thisInvalidate(); } //新闻被点击 事件触发方法 void NewsStage_Click(object sender EventArgs e) { if (_NewsID>=&&_NewsTitle!="") { NewsEventArg myArgs = new NewsEventArg(_NewsID_NewsTitle); NewsClicked(this myArgs); } } private int _NewsID = ; [Description("新闻ID") Category("Appearance")] public int NewsID { get { return _NewsID; } set { _NewsID = value; thisInvalidate(); } } /// <summary> /// 新闻标题 /// </summary> private string _NewsTitle = ""; [Description("新闻标题") Category("Appearance")] public string NewsTitle { get { return _NewsTitle; } set { _NewsTitle = value; thisInvalidate(); } } private Color _MouseOnColor = new Color(); [Description("鼠标划上的样色") Category("Appearance")] public Color MouseOnColor { get { return _MouseOnColor; } set { _MouseOnColor = value; } } protected override void OnPaint(PaintEventArgs pe) { baseOnPaint(pe); g = thisCreateGraphics(); if (isMouseOn) { gDrawString(_NewsTitle thisFont new SolidBrush(this_MouseOnColor) new PointF( )); } else { gDrawString(_NewsTitle thisFont new SolidBrush(thisForeColor) new PointF( )); } } protected void Dispose() { gDispose(); } } public partial class NewsEventArg : EventArgs { public int NewsID = ; public string NewsTitle = ""; public NewsEventArg(int newsIDstring newsTitle){ NewsID = newsID; NewsTitle = newsTitle; } } }