Hello, I use custom events all the time but with the following piece of code I am not sure what is wrong. I am not able to Add an event handler to an instance of this class.
Code:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace CustomNotepad2 { public partial class frmGoTo : Form { public frmEditor FormEditor = new frmEditor(); public delegate void GoToEventHandler(object sender, GoToEventArgs e); public GoToEventHandler GoToEvent; public frmGoTo() { InitializeComponent(); } private void btnGoTo_Click(object sender, EventArgs e) { OnGoTo(new GoToEventArgs(int.Parse(txtLineNumber.Text.Trim()))); } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } protected virtual void OnGoTo(GoToEventArgs e) { if (GoToEvent != null) { GoToEvent(this, e); } } } public class GoToEventArgs : EventArgs { int _line = 0; public GoToEventArgs(int line) { _line = line; } public int GoToLine { get { return _line; } } } }




Reply With Quote