Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
UserControl is a UC Component,where i have taken a textbox.So how can i create a new event of this textbox which is in UserControl through delegate.
Posted

1 solution

Have a look at this code, it might give you an idea of how to get started:
C#
public class UserControl : Control
{
   private TextBox textBox1;
   public UserControl()
   {
      textBox1 = new System.Windows.Forms.TextBox();
      textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(textBox1_KeyPress);
   }

   public delegate void CustomKeyPressEventHandler(object sender, System.Windows.Forms.KeyPressEventArgs e);

   public event CustomKeyPressEventHandler OnCustomKeyPress;

   private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
   {
      if (OnCustomKeyPress != null)
         OnCustomKeyPress(sender, e);
   }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900