【问题标题】:Why is the empty result turning?为什么空结果会转动?
【发布时间】:2017-03-05 22:58:05
【问题描述】:

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

我想要 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; }

有什么问题?

【问题讨论】:

  • 您正在每个地方实例化一个新的 CommClass 实例。 workingFunction 没有使用您在 button1_click 中声明的同一个 CommClass

标签: c# string properties prop


【解决方案1】:

您需要传入参数。在 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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    • 2017-06-05
    • 2019-04-16
    • 2019-07-01
    • 1970-01-01
    相关资源
    最近更新 更多