Home >Backend Development >C++ >How to Pass Values Between Forms in C#?
In order to pass the value between Form1 and Form2, we will use the following methods:
Display FORM2 in a modular manner to ensure that Form1 keeps non -activity status.
<code class="language-csharp">// Form 1 // 在按钮点击事件中 using(Form2 form2 = new Form2()) { if(form2.ShowDialog() == DialogResult.OK) { someControlOnForm1.Text = form2.TheValue; } }</code>If the user clicks the "OK" button on Form2, the
<code class="language-csharp">// Form 2 // 创建一个公共属性来提供值 public string TheValue { get { return someTextBoxOnForm2.Text; } }</code>method returns
.
ShowDialog()
). ShowDialog()
This method provides a simple and effect way to pass value in C#. Remember to reply DialogResult.OK
and The above is the detailed content of How to Pass Values Between Forms in C#?. For more information, please follow other related articles on the PHP Chinese website!