我是c#的新手,我只需要一些基本的东西。我试图从按钮单击调用方法,我不知道我是否在Program.cs或Form1.cs中声明了一个对象和方法c#如何在Windows窗体应用程序中使用方法?
这是我迄今为止所做的。
public partial class frmMain : Form
{
Form form = new Form();
public frmMain()
{
InitializeComponent();
}
private void btnCalc_Click(object sender, EventArgs e)
{
txtC.Text = form.CalcHypotenuse(double.Parse(txtA.Text), double.Parse(txtB.Text));
}
}
public string CalcHypotenuse(double sideA, double sideB)
{
double hypotenuse = Math.Sqrt((sideA * sideA) + (sideB * sideB));
string hypotenuseString = hypotenuse.ToString();
return hypotenuseString;
}
这是否为您提供了错误? – Sami
是的两个错误,“名称空间不能直接包含成员,如字段或方法”和“'表'不包含'CalcHypotenuse'的定义”“ –