通过UserControl文本框的委托创建一个新事件 [英] Create a new event through delegate,of textbox of UserControl

查看:51
本文介绍了通过UserControl文本框的委托创建一个新事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UserControl是一个UC组件,我在其中放置了一个文本框.那么如何通过委托在UserControl中创建此文本框的新事件.

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.

推荐答案

看一下这段代码,它可能会给您一个入门的思路:
Have a look at this code, it might give you an idea of how to get started:
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);
   }
}


这篇关于通过UserControl文本框的委托创建一个新事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆