如何在用户控件里写个button然后写个自己的事件,委托??? 在用户控件里写个button然后写个自己的事件,委托,写完后把控件拉到form主窗体中,在这个用户控件中可以找到自己写的事件。然后调用,效果和button里click事件一样的效果就可以。 这样要怎么写,求详细解释,初学者。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 声明一个事件,button的单击事件绑定一个方法,该方法执行这个事件,相当于外部调用窗体,这个用户控件的这个事件,其实执行的,就是其内部button的单击事件 自定义的 public partial class UserControl1 : UserControl { public event EventHandler MyClick; public UserControl1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (MyClick != null) MyClick(sender, e); } }使用 UserControl1 btn = new UserControl1(); btn.Parent = this; btn.MyClick += new EventHandler( delegate(object obj, EventArgs se) { MessageBox.Show("ok"); }); 我重写一个QT的QWidget类或QPushButton类的时候,就常常需要重新实现其原有的事件(信号),大致和我说的,还有3L的实例,差不多。 将Button按钮的访问权限设置为Public 然后就可以在父窗口的代码中关联按钮的事件处理程序userControl1.Button1.Click += MyFunction datagridview中关于键盘按键的操作 datagrid 如何在鼠标滑动时调用后台方法 一个VS系统的问题,急!!! C#模拟post总是未登录 关于OleDbDataAdapter的update方法 请问各位,如何跟据域名得到当前服务器的IP? 有关数据库的问题,请高手指教. 有关在c#中使用WMI的特权问题,哪位前辈指点一下? Dev控件库中Grid控件中下拉框级联显示 散分散分! tabcontrol控件,如何用代码让某个选项卡成为当前项呢? 为何新建一个窗体后,总是显式“无法用设计器打开”,我发现总是因为 “名称空间”错了,后面多加上了 .Form
{
public event EventHandler MyClick;
public UserControl1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
if (MyClick != null)
MyClick(sender, e);
}
}使用 UserControl1 btn = new UserControl1();
btn.Parent = this;
btn.MyClick += new EventHandler(
delegate(object obj, EventArgs se)
{
MessageBox.Show("ok");
});
userControl1.Button1.Click += MyFunction