在表单之间传递变量。 [英] Passing variables between forms.
问题描述
任何人都可以推荐一个最好的方法将字符串传回
调用类(windows窗体)来自一个使用ShowDialog以模态方式显示
的对话框? />
" Steve" <豪****** @ cmmts.com>在消息中写道
news:0b **************************** @ phx.gbl ... < blockquote class =post_quotes>任何人都可以推荐使用ShowDialog以模态方式显示的对话框中将字符串传回
调用类(windows窗体)的最佳方法吗?
当你的(模态)关闭时,它不会被销毁。你仍然可以阅读
属性
的那种形式。
Hans Kesting
>
你可以使字符串成为实现
第二种形式的类的公共属性,然后在调用ShowDialog()之前你可以分配一个值
该属性,并且从ShowDialog()返回时,您可以从
财产中读取该值。
MyForm oForm = new MyForm();
oForm.ShowDialog();
SomeVariable = oForm.StringData;
希望这有帮助
Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza
***通过Developersdex发送 http://www.developersdex.com ***
不要刚参加USENET ......获得奖励!
>
你好史蒂夫!
任何人都可以推荐一个将字符串传回
调用类(windows窗体)的最佳方法,该对话框是
使用ShowDialog以模态方式显示?
尝试将ShowDialog()方法重载为ShowDialog(输出字符串超出范围)
显示的模态形式和在他们返回之前填充变量outtring:
公共类MyDialog:表格
{
public DialogResult ShowDialog(out string outstring)
{
DialogResult ret;
ret = this.ShowDialog();
outstring = this.TextBox1.Text ;
返回ret;
}
}
公共类CallerForm:表格
{
...
string outtring;
MyDialog dlg = new MyDialog();
dlg。 ShowDialog(out outtring);
MessageBox.Show(outstring);
...
}
- -
WBR,Roman S. Golub在
ICQ UIN 63253392
go *** *************@arhcity.ru
Can anyone recommend the best way to pass a string back to
the calling class (windows form) from a dialog that was
shown modally using ShowDialog?
"Steve" <ho******@cmmts.com> wrote in message
news:0b****************************@phx.gbl...Can anyone recommend the best way to pass a string back to
the calling class (windows form) from a dialog that was
shown modally using ShowDialog?
When your (modal) for closes, it is not destroyed. You can still read
properties
of that form.
Hans Kesting
Hi,
You can make the string a public property of the class implementing the
second form, then before calling ShowDialog() you can assign a value the
the property and on return from ShowDialog() you can read the value from
the property.
MyForm oForm = new MyForm();
oForm.ShowDialog();
SomeVariable = oForm.StringData;
Hope this helps
Chris Taylor
http://www.xanga.com/home.aspx?user=taylorza
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!
Hello Steve!
Can anyone recommend the best way to pass a string back to
the calling class (windows form) from a dialog that was
shown modally using ShowDialog?
Try to overload the ShowDialog() method as ShowDialog(out string outstring)
for shown modally form and fill variable outstring before them return:
public class MyDialog : Form
{
public DialogResult ShowDialog(out string outstring)
{
DialogResult ret;
ret = this.ShowDialog();
outstring= this.TextBox1.Text;
return ret;
}
}
public class CallerForm : Form
{
...
string outstring;
MyDialog dlg = new MyDialog();
dlg.ShowDialog(out outstring);
MessageBox.Show(outstring);
...
}
--
WBR, Roman S. Golubin
ICQ UIN 63253392
go****************@arhcity.ru
这篇关于在表单之间传递变量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!