c# - 不可调用成员 'System.Windows.Forms.Control.Text' 不能像方法一样使用。在 C# 中

标签 c# winforms

我的 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/

相关文章:

C# winforms 在特定情况下不捕获异常

c# - 将数据从子窗体发送到父窗体 TextBox

c# - 理解有漏洞的应用程序的 Performance Profiler 输出?

c# - TruncateTime(System.Nullable`1[System.DateTime] )' has no supported translation to SQL.'

c# - 哈希表到字典的转换

c# - 以编程方式设置控制台窗口大小和位置

c# - Windows 语音识别 C#

c# - 在 C# 中开发 winform 应用程序是否有任何标准的屏幕分辨率

c# - 如何在 WinForms 中扩展控件?

c# - Xamarin.Android JmDNS 绑定(bind)问题