Create events for windows User Control.Urgent!!!
-
How do we create events for a user control which is dynamically added? Thanks in advance R.K
In Your control which is too added class;- Declare delegate:- public delegate void ShowTextEvent(string str,EventArgs e); Declare event:- public void ShowTextEvent MyEvent; ///////////////////////////////////////////////////////////////////// void somemethod() { //////////////////////////////// Control is added Controls.Add(NewControl); /////////////////////////////// Setting Event to this. NewControl.MyEvent+=new ShowTextEvent(OnMyEvent); } ////Handler void OnMyEvent(string str,EventArgs e) { }
-
In Your control which is too added class;- Declare delegate:- public delegate void ShowTextEvent(string str,EventArgs e); Declare event:- public void ShowTextEvent MyEvent; ///////////////////////////////////////////////////////////////////// void somemethod() { //////////////////////////////// Control is added Controls.Add(NewControl); /////////////////////////////// Setting Event to this. NewControl.MyEvent+=new ShowTextEvent(OnMyEvent); } ////Handler void OnMyEvent(string str,EventArgs e) { }
Hi aslam, i have a user control created with a button on it. I am creating an instance of this user control using statments IComponent newComponent = Activator.CreateInstance(componentClass, objparams) as IComponent; now i need to add event to this component. i want the click event of the user control. please help. thanks in advance.