打开时如何将字符串值发送到另一个表单? [英] How to send string value to another form when opening it?
本文介绍了打开时如何将字符串值发送到另一个表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Form1,我打开一个新的Form2,点击按钮。
每次我点击Form1中的那个按钮,我想传递一个
字符串值到Form2代码。
如何做到这一点?
我试图研究这个,并尝试了几个例子,但我发现的例子并不完全相同。 br />
请帮忙,并提前致谢。
Simo
我尝试过:
从网上尝试了一些例子。试图弄清楚自己,但没有线索...
I have a Form1 where i open a new Form2 with button click.
Every time i click that button in Form1, i would like to pass a
string value to Form2 code.
How can this be done?
I have tried to study this, and tried several examples, but the examples i found was not quite the same.
Please help, and thanks in advance.
Simo
What I have tried:
Tried some examples from the net. Tried to figure it out myself, but have no clue...
推荐答案
为接受字符串参数的第二个表单创建一个构造函数:
Create a constructor for the second form which accepts a string parameter:
public Form2(string s)
{
// Do something with your string
...
}
然后在构造表单实例时,传递您的值:
Then when you construct the form instance, pass your value:
Form2 myForm2Instance = new Form2("Hello World!");
myForm2Instance.Show();
你好,
谷歌有几个例子。
试试这些
1. 传递数据表格
2. 如何将一个窗体的值传递给另一个窗体形式
谢谢
Hello ,
There are several example available in Google .
try these
1. Passing Data Between Forms
2. How to pass the Value one form to another form in windows form
Thanks
这篇关于打开时如何将字符串值发送到另一个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文