我的 C# 程序是这样说的。我不知道如何解决这个问题,因为我是 c# 的新手。请帮助我T_T。谢谢!
public partial class Form1 : Form
{
private void btnGenerateUserID_Click(object sender, EventArgs e)
{
textBox4.Text(User.GenerateUserID);
}
private void btnGenerateUsername_Click(object sender, EventArgs e)
{
textBox5.Text(User.GenerateUsername(Name.Text, MI.Text, Lastname.Text));
}
}
最佳答案
TextBox.Text
是一个属性,它不是一个方法。您需要为该属性分配值。
textBox4.Text = User.GenerateUserID; //assuming its string or call User.GetUserID.ToString();
如果 User.GetUserID
是一个方法,那么您需要这样调用它:
textBox4.Text = User.GenerateUserID();
如果返回值不是字符串,那么你可以调用 ToString
,如下所示:
textBox4.Text = User.GenerateUserID().ToString(); //check for null before calling
//ToString
做同样的事情:
textBox5.Text = User.GenerateUsername(Name.Text, MI.Text, Lastname.Text);
关于c# - 不可调用成员 'System.Windows.Forms.Control.Text' 不能像方法一样使用。在 C# 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21434000/