【问题标题】:c# navigation between formsc# 在表单之间导航
【发布时间】:2019-02-21 19:40:35
【问题描述】:

我对如何在 c# 中的表单之间导航感到困惑

我想做以下事情:

  1. Form1打开Form2并在原来Form1的顶部创建Form2,然后返回Form1,用户不得使用Form1,直到他们关闭子Form2 以返回Form1

  2. 使用相同的场景,但我可以将参数从Form2 传递给Form1

我搜索但我认为不清楚我发现有一个叫做 MDI Parent And Child 的东西就像answer here 但是

我不希望孩子在原来的里面

我不会改变原来的风格,变成灰色的

那样我认为我需要使用的是NOT MDI Parent and Child

请帮助我欣赏带有示例的长解释说明

【问题讨论】:

标签: c# .net-4.0


【解决方案1】:

这假设您对Form2 感兴趣的数据可以通过读/写属性访问。在我的示例中,我将其显示为一个名为 UsefulData 的简单字符串属性。这是执行您所要求的常规方法:

  private void button1_Click(object sender, EventArgs e)
  {
      var dialog = new Form2();                       //create an instance of Form2
      dialog.UsefulData = "Some Useful Data";         //set one or more properties of that form
      string result = "No Result Yet";                //a place to store the eventual data from Form2
      if (dialog.ShowDialog(this) == DialogResult.OK) //passing "this" properly parents the dialog to your Form1
      {                                               //note that I only get the data if the user pressed OK
          result = dialog.UsefulData;                 //get the data
      }
      //do something with that result
  }

你去!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    • 2021-11-29
    相关资源
    最近更新 更多