为什么空的结果在转?

Why is the empty result turning?

首先,我的英语不好,对不起。

我希望 textbox(在 Form2.cs 中)文本显示 MainForm.cs 当我应用以下代码时,显示空白消息。

MainForm.cs

private void btnFilitre_ItemClick(object sender,DevExpress.XtraBars.ItemClickEventArgs e)
{
     ...
     Form2 f2 = new Form2();
     f2.Show();
}

private void workingFunction()
{
    CommClass com = new CommClass();
    MessageBox.Show(comm.Sorgu ); 
}

Form2.cs

 private void button1_Click(object sender, EventArgs e)
 {
     Form1 f1 = new Form1();
     CommClass comm = new CommClass();
     comm.Sorgu = textBox1.Text;
     f1.workingFunction();
     Hide();
 }

CommClass.cs

 public string Sorgu { get; set; }

问题是什么?

您需要传入参数。在 Form1 中进行以下更改:

public void workingFunction(CommClass comm)
{
    MessageBox.Show(comm.Sorgu ); 
}

并且在 Form2 中,您需要跟踪您的 Form1 引用,而不是创建一个新引用,然后传入您的 CommClass 对象:

private void button1_Click(object sender, EventArgs e)
{
    CommClass comm = new CommClass();
    comm.Sorgu = textBox1.Text;
    f1.workingFunction(comm);
    Hide();
}