从表格中返回值? [英] Return Values From Form?
问题描述
您好,
我有一个Windows窗体应用程序(VS2005),我需要在
之后执行...
1.使用主窗体启动。
2.让用户选择一个文件,然后调出第二张表格
modally(Form1。 ShowDialog())以便用户可以自定义
选项。
3.我可以将第二种形式的选项存储在许多不同的
$ b $中b方式,但是一旦模态形式
关闭,我必须让它们回到主窗体。选项是列标题名称,现在我是
选择将它们存储在通用列表< string>中。
到目前为止我做得很好,但是现在我需要找出最好的方法,一旦用户点击
继续,
将选择返回到主窗体。我在第二个表单上调用this.Close()。
我想创建列表然后将引用传递给
模态表单'' s构造函数:" ref List< stringMyList"。但这并不是
工作,因为列表的范围不是模态形式的'
构造函数。因此,当其他事件发生时,我无法与其进行交互
在表单上,例如按钮点击。
另一种方式是创建和修改第二种形式的清单
然后简单地返回它,但据我所知,使用表格时不能这样做
(普通旧函数不会有问题)。
没有返回(MyList )关闭表格时会有效吗?
对吧?
解决这个问题的好方法是什么?
Hello,
I have a windows forms application (VS2005) where I need to do the
following...
1. Startup with a main form.
2. Have the user to select a file and then bring up a second form
modally (Form1.ShowDialog()) so that the user can make custom
selections.
3. I can store the selections from the second form in many different
ways, but I have to get them back to the main form once the modal form
is closed. The selections are column header names, and right now I am
choosing to store them in a Generic List<string>.
I am doing fine so far, but now I need to figure out the best way to
get the selections back to the main form, once the user clicks
"Continue" and I call this.Close() on the second form.
I thought about creating the list and then passing a reference to the
modal form''s constructor: "ref List<stringMyList". But this doesn''t
work because the list is not scoped outside of the modal form''s
constructor. And so I cannot interact with it when other events occur
on the form, like for example, a button click.
Another way would be create and modify the list within the second form
and then simply "return" it, but as far as I know one cannot do that
when using forms (would not be a problem with plain old functions).
There is not a return(MyList) that will work when closing a form,
right?
What would be a good way to tackle this?
推荐答案
Joey,
为什么不在表单上公开一个会暴露
$ b $的属性b选择的格式是否易于使用?表单
引用仍然有效,您仍然可以访问
表格中公开的属性。
希望这有助于。
-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com
< jo ********* @ topscene.com写了留言
新闻:11 ********************* @ 75g2000cwc.googlegrou ps.com ...
Joey,
Why not just expose a property on your form that will expose the
selections in a format that is easy for you to work with? The form
reference is still valid, and you can still access the properties exposed on
your form.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<jo*********@topscene.comwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
您好,
我有一个Windows窗体应用程序(VS2005),我需要在那里做
以下...
1.使用主表单启动。
2.让用户选择一个文件,然后调出第二个表单
modally(Form1.ShowDialog())以便用户可以自定义
选项。
3.我可以存储第二种形式的选择在许多不同的方式,但我必须让他们回到主要形式一旦莫代尔形式
已关闭。选项是列标题名称,现在我是
选择将它们存储在通用列表< string>中。
到目前为止我做得很好,但是现在我需要找出最好的方法,一旦用户点击
继续,
将选择返回到主窗体。我在第二个表单上调用this.Close()。
我想创建列表然后将引用传递给
模态表单'' s构造函数:" ref List< stringMyList"。但这并不是
工作,因为列表的范围不是模态形式的'
构造函数。因此,当其他事件发生时,我无法与其进行交互
在表单上,例如按钮点击。
另一种方式是创建和修改第二种形式的清单
然后简单地返回它,但据我所知,使用表格时不能这样做
(普通旧函数不会有问题)。
没有返回(MyList )关闭表格时会有效吗?
对吗?
解决这个问题的好办法是什么?
Hello,
I have a windows forms application (VS2005) where I need to do the
following...
1. Startup with a main form.
2. Have the user to select a file and then bring up a second form
modally (Form1.ShowDialog()) so that the user can make custom
selections.
3. I can store the selections from the second form in many different
ways, but I have to get them back to the main form once the modal form
is closed. The selections are column header names, and right now I am
choosing to store them in a Generic List<string>.
I am doing fine so far, but now I need to figure out the best way to
get the selections back to the main form, once the user clicks
"Continue" and I call this.Close() on the second form.
I thought about creating the list and then passing a reference to the
modal form''s constructor: "ref List<stringMyList". But this doesn''t
work because the list is not scoped outside of the modal form''s
constructor. And so I cannot interact with it when other events occur
on the form, like for example, a button click.
Another way would be create and modify the list within the second form
and then simply "return" it, but as far as I know one cannot do that
when using forms (would not be a problem with plain old functions).
There is not a return(MyList) that will work when closing a form,
right?
What would be a good way to tackle this?
你能解释一下吗?
Nicholas Paldino [.NET / C#MVP]写道:
Could you explain a little more?
Nicholas Paldino [.NET/C# MVP] wrote:
Joey,
为什么不在表单上公开一个属性,以一种格式公开
选项你很容易合作吗?表单
引用仍然有效,您仍然可以访问
表格中公开的属性。
希望这有助于。
-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com
< jo ********* @ topscene.com写了留言
新闻:11 ********************* @ 75g2000cwc.googlegrou ps.com ...
Joey,
Why not just expose a property on your form that will expose the
selections in a format that is easy for you to work with? The form
reference is still valid, and you can still access the properties exposed on
your form.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<jo*********@topscene.comwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
您好,
我有一个Windows窗体应用程序(VS2005),我需要在那里做
以下...
1.使用主表单启动。
2.让用户选择一个文件,然后调出第二个表单
modally(Form1.ShowDialog())以便用户可以自定义
选项。
3.我可以存储第二种形式的选择在许多不同的方式,但我必须让他们回到主要形式一旦模态形式
关闭。选项是列标题名称,现在我是
选择将它们存储在通用列表< string>中。
到目前为止我做得很好,但是现在我需要找出最好的方法,一旦用户点击
继续,
将选择返回到主窗体。我在第二个表单上调用this.Close()。
我想创建列表然后将引用传递给
模态表单'' s构造函数:" ref List< stringMyList"。但这并不是
工作,因为列表的范围不是模态形式的'
构造函数。因此,当其他事件发生时,我无法与其进行交互
在表单上,例如按钮点击。
另一种方式是创建和修改第二种形式的清单
然后简单地返回它,但据我所知,使用表格时不能这样做
(普通旧函数不会有问题)。
没有返回(MyList )关闭表格时会有效,
对吧?
解决这个问题的好办法是什么?
Hello,
I have a windows forms application (VS2005) where I need to do the
following...
1. Startup with a main form.
2. Have the user to select a file and then bring up a second form
modally (Form1.ShowDialog()) so that the user can make custom
selections.
3. I can store the selections from the second form in many different
ways, but I have to get them back to the main form once the modal form
is closed. The selections are column header names, and right now I am
choosing to store them in a Generic List<string>.
I am doing fine so far, but now I need to figure out the best way to
get the selections back to the main form, once the user clicks
"Continue" and I call this.Close() on the second form.
I thought about creating the list and then passing a reference to the
modal form''s constructor: "ref List<stringMyList". But this doesn''t
work because the list is not scoped outside of the modal form''s
constructor. And so I cannot interact with it when other events occur
on the form, like for example, a button click.
Another way would be create and modify the list within the second form
and then simply "return" it, but as far as I know one cannot do that
when using forms (would not be a problem with plain old functions).
There is not a return(MyList) that will work when closing a form,
right?
What would be a good way to tackle this?
Joey,
表单是一个对象,就像其他任何东西一样。只需将您的类型定义为
公开您可以在ShowDialog返回后调用的属性/方法
将为您提供对话框中的值。
-
- Nicholas Paldino [.NET / C#MVP]
- mv *@spam.guard.caspershouse.com
< jo ********* @ topscene.comwrote in message
新闻:11 ********************** @ 35g2000cwc.googlegro ups.com ...
Joey,
A form is an object, like anything else. Just define your type to
expose a property/method that you can call after ShowDialog returns which
will give you the values from the dialog.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<jo*********@topscene.comwrote in message
news:11**********************@35g2000cwc.googlegro ups.com...
你能解释一下吗?
Nicholas Paldino [.NET / C#MVP]写道:
Could you explain a little more?
Nicholas Paldino [.NET/C# MVP] wrote:
> Joey,
为什么不在表单上公开一个属性,以便以易于使用的格式公开
选项?表格
参考仍然有效,您仍然可以访问表格上公开的财产。
希望这会有所帮助。
> -
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse。 com
< jo ********* @ topscene.com写了留言
新闻:11 ************ *********@75g2000cwc.googlegro ups.com ...
>Joey,
Why not just expose a property on your form that will expose the
selections in a format that is easy for you to work with? The form
reference is still valid, and you can still access the properties exposed
on
your form.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<jo*********@topscene.comwrote in message
news:11*********************@75g2000cwc.googlegro ups.com...
你好,
我有一个Windows窗体应用程序(VS2005),我需要在其中执行
以下...
1.使用主窗体启动。
2.让用户选择一个文件,然后调出第二个表格
modally(Form1.ShowDialog()),这样用户就可以自定义
选择。
3.我可以用许多不同的
方式存储第二种形式的选项,但是我必须在模态形式后将它们恢复到主形式
已关闭。选项是列标题名称,现在我是
选择将它们存储在通用列表< string>中。
到目前为止我做得很好,但是现在我需要找出最好的方法,一旦用户点击
继续,
将选择返回到主窗体。我在第二个表单上调用this.Close()。
我想创建列表然后将引用传递给
模态表单'' s构造函数:" ref List< stringMyList"。但这并不是
工作,因为列表的范围不是模态形式的'
构造函数。因此,当其他事件发生时,我无法与其进行交互
在表单上,例如按钮点击。
另一种方式是创建和修改第二种形式的清单
然后简单地返回它,但据我所知,使用表格时不能这样做
(普通旧函数不会有问题)。
没有返回(MyList )关闭表格时会有效吗?
对吗?
解决这个问题的好办法是什么?
Hello,
I have a windows forms application (VS2005) where I need to do the
following...
1. Startup with a main form.
2. Have the user to select a file and then bring up a second form
modally (Form1.ShowDialog()) so that the user can make custom
selections.
3. I can store the selections from the second form in many different
ways, but I have to get them back to the main form once the modal form
is closed. The selections are column header names, and right now I am
choosing to store them in a Generic List<string>.
I am doing fine so far, but now I need to figure out the best way to
get the selections back to the main form, once the user clicks
"Continue" and I call this.Close() on the second form.
I thought about creating the list and then passing a reference to the
modal form''s constructor: "ref List<stringMyList". But this doesn''t
work because the list is not scoped outside of the modal form''s
constructor. And so I cannot interact with it when other events occur
on the form, like for example, a button click.
Another way would be create and modify the list within the second form
and then simply "return" it, but as far as I know one cannot do that
when using forms (would not be a problem with plain old functions).
There is not a return(MyList) that will work when closing a form,
right?
What would be a good way to tackle this?
这篇关于从表格中返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!