这是我离开IDE编码很长时间后开始的C#Web表单项目...
我正在尝试制作一个简单的自定义对话框类。这是我的代码。
public static class Dialogo
{
public static int show ()
{
Form dialogo = new Form();
dialogo.Width = 300;
dialogo.Height = 300;
Button btnSim = new Button() { Text = "Sim", Left = 30, Width = 100 };
Button btnNao = new Button() { Text = "Não", Left = 150, Width = 100 };
dialogo.Controls.Add(btnSim);
dialogo.Controls.Add(btnNao);
dialogo.ShowDialog();
// the following two lines are the problematic ones
btnSim += new EventHandler(btnSim_Click);
btnNao += new EventHandler(btnNao_Click);
return -1;
}
}
它在括号内加了下划线,并且消息说:
名称btnSim_Click'在当前上下文中不存在
问题是我试图在代码中添加以下内容,但不允许我将其放置在任何位置(它总是说这是错误的):
private int btnNao_Click (object sender, EventArgs e)
{
return 0;
}
private int btnSim_Click (object sender, EventArgs e)
{
return 1;
}
我的目标是两个按钮btnSim和btnNao各自返回不同的值(例如1和0)。>>
我在做什么错?
这是我在远离IDE编码很长时间之后开始的C#Web表单项目。我试图制作一个简单的自定义对话框类。这是我的代码。公共静态类Dialogo {...
EventHandler
是返回void
的方法的委托。