Using System;
Using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. text; using System. windows. forms; namespace ClientControl {// 1. define the delegate public delegate void NewsClickEventHandle (object sender, NewsEventArg args); public partial class NewsStage: Control {// 2. define the event public event NewsClickEventHandle NewsClicked; private Graphics g; private bool isMouse On = false; public NewsStage () {InitializeComponent (); // 3. event trigger. If event registration is missing, you only need to register the event and edit the event handler when referencing the control in other forms. You can compare this with the previous blog. click + = new EventHandler (NewsStage_Click); this. mouseMove + = new MouseEventHandler (NewsStage_MouseMove); this. mouseLeave + = new EventHandler (NewsStage_MouseLeave);} void NewsStage_MouseLeave (object sender, EventArgs e) {isMouseOn = false; this. invalidate ();} void NewsStage_M OuseMove (object sender, MouseEventArgs e) {isMouseOn = true; this. invalidate () ;}// Method for triggering a news Click Event void NewsStage_Click (object sender, EventArgs e) {if (_ NewsID> = 0 & _ NewsTitle! = "") {NewsEventArg myArgs = new NewsEventArg (_ NewsID, _ NewsTitle); NewsClicked (this, myArgs);} private int _ NewsID = 0; [Description ("News ID"), Category ("Appearance")] public int NewsID {get {return _ NewsID;} set {_ NewsID = value; this. invalidate () ;}/// <summary> // news title /// </summary> private string _ NewsTitle = ""; [Description ("news title"), Category ("Appearance")] public string NewsTitle {get {return _ NewsTitle;} set {_ NewsTitle = value; this. invalidate () ;}} private Color _ MouseOnColor = new Color (); [Description ("Mouse Color"), Category ("Appearance")] public Color MouseOnColor {get {return _ MouseOnColor;} set {_ MouseOnColor = value ;}} protected override void OnPaint (PaintEventArgs pe) {base. onPaint (pe); g = this. createGraphics (); if (isMouseOn) {g. drawString (_ NewsTitle, this. font, new SolidBrush (this. _ MouseOnColor), new PointF (0, 0);} else {g. drawString (_ NewsTitle, this. font, new SolidBrush (this. foreColor), new PointF (0, 0) ;}} protected void Dispose () {g. dispose () ;}} public partial class NewsEventArg: EventArgs {public int NewsID = 0; public string NewsTitle = ""; public NewsEventArg (int newsID, string newsTitle) {NewsID = newsID; newsTitle = newsTitle ;}}}