c#用户控件里有个按钮,当窗体运行时通过程序自动生成了一个用户控件,然后这里面的按钮添加委托事件
委托的类publicdelegatevoidDelegateClassHandle();publicclassEmployee{publiceventDelegateCl...
委托的类
public delegate void DelegateClassHandle();
public class Employee
{
public event DelegateClassHandle PlayGame;
public void Games()
{
if (PlayGame != null)
{
PlayGame();
}
}
}
public class Admin
{
public void Notify()
{
MessageBox.Show("jhgj");
}
}
然后进行委托
Employee employee = new Employee();
Admin admin = new Admin();
然后在 用户控件添加委托代码 出错,
UClistview uclv = new UClistview();
uclv.Location = new Point(lineid * 210, 0);
uclv.button1_Click_1 += new DelegateClassHandle(employee.Games);
button1_Click_1 为代码组,无法赋值 展开
public delegate void DelegateClassHandle();
public class Employee
{
public event DelegateClassHandle PlayGame;
public void Games()
{
if (PlayGame != null)
{
PlayGame();
}
}
}
public class Admin
{
public void Notify()
{
MessageBox.Show("jhgj");
}
}
然后进行委托
Employee employee = new Employee();
Admin admin = new Admin();
然后在 用户控件添加委托代码 出错,
UClistview uclv = new UClistview();
uclv.Location = new Point(lineid * 210, 0);
uclv.button1_Click_1 += new DelegateClassHandle(employee.Games);
button1_Click_1 为代码组,无法赋值 展开
1个回答
展开全部
uclv.button1_Click_1是具体的方法名吧,应该是绑定事件的:
uclv.button1.Click+= new DelegateClassHandle(employee.Games);
uclv.button1.Click+= new DelegateClassHandle(employee.Games);
追问
button1 是用户控件中的一个按钮,换成uclv.button1.Click 还是不行
我应该怎么把 button1 给public 一下,现在只能把 click给public
追答
写成属性就好了
pulic Button Button1
{
get;
set;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询