如何使用构造函数 c# 更改用户控件中的按钮文本?

How to change button text in a user control using constructor c#?

我制作了这个包含按钮的用户控件

using System.Windows.Forms;
namespace test2
{
public partial class testme : UserControl
{
    public testme()
    {
        InitializeComponent();
    }
    public testme(string x)
    {
        button1.Text = x;
    }
}
}

然后我尝试使用构造函数更改用户控件中的按钮

using System;
using System.Windows.Forms;
namespace test2
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {

        testme v = new testme("New Text");

}
}
}

但是当我在 运行 中点击按钮 1 时,我收到了这个错误信息 对象引用未设置到对象的实例

重载的构造函数需要调用带InitializeComponent();的构造函数,这叫做Constructor Chaining,把这一行改成:

public testme(string x) : this()