C# 无法更改弹出窗口上的标签文本

C# 无法更改弹出窗口上的标签文本,c#,winforms,label,C#,Winforms,Label,我不明白它为什么不起作用。 我想将标签的文本设置在弹出窗体的外部 class BaseForm : Form {} public class BasePopup { private Form popupForm; private Panel controlPanel; private Label controlLabel; public BasePopup() { popupForm = new BaseForm {

我不明白它为什么不起作用。 我想将标签的文本设置在弹出窗体的外部

class BaseForm : Form
{}

public class BasePopup
{
    private Form popupForm;
     private Panel controlPanel;
    private Label controlLabel; 

    public BasePopup()
    {
        popupForm = new BaseForm
        {
           ...
        };

        controlPanel = new Panel { Dock = DockStyle.Fill, BorderStyle = BorderStyle.Fixed3D };
        popupForm.Controls.Add(controlPanel);

        controlLabel = new Label { Location = new Point(30, 30), Text = "AAA" };
        controlPanel.Controls.Add(controlLabel);
    }
 }

 public string ControlLabelText
    {
        get { return controlLabel.Text; }
        set { controlLabel.Text = value; }
    }

public class ComboBoxPopup : BasePopup
{
}
用法:

 var txp = new ComboBoxPopup();
        txp.ControlLabelText = "Please select the language";
        new ComboBoxPopup().ShowDialog(this);
文本保存在此处-
controlLabel.Text=value
但标签的文字并没有改变。我尝试了
Application.DoEvents()
,但没有成功。

而不是

new ComboBoxPopup().ShowDialog(this);
你必须说明

txp.ShowDialog(this);

否则,您将创建并显示弹出窗口的新实例,并且不会显示对第一个实例的标签更改。

那么,您的问题的答案是,
controlLabel
未放置在
BasePopup
上。但是,您的问题的解决方案有很大不同。看来你真正想要的是:

public class BasePopup : BaseForm
{
    private Panel controlPanel;
    private Label controlLabel; 

    public BasePopup()
    {
        controlPanel = new Panel { Dock = DockStyle.Fill, BorderStyle = BorderStyle.Fixed3D };
        this.Controls.Add(controlPanel);

        controlLabel = new Label { Location = new Point(30, 30), Text = "AAA" };
        controlPanel.Controls.Add(controlLabel);
    }
 }

该死多么可耻的错误!非常感谢,没问题。如果答案对你有效,请接受。谢谢