在两个表单之间传递数据 [英] Pass Data between 2 forms

查看:81
本文介绍了在两个表单之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我知道这个问题是在2个星期前被其他人问过的。但我需要一些额外的帮助。
需要一些额外的帮助。我有一个正在开发的程序,将会打开多个不同形式的
。但就目前而言,我只有两种形式。一个是主窗口的

,另一个设置了一些喜欢的名字和电子邮件

地址。


当有人打开时这个窗口,并在这个页面上输入值,我希望它能够在主页上设置公共变量的值。


我'假设这可以做到,但是怎么做?


在主页面上,我设置了一个公共form2作为2ndForm = new secondForm


我可以从主页面访问第二个表单属性,但反之亦然。


?????????


谢谢

Yeah, I know this question was asked by someone elselike 2 weeks ago. But I
need some additional help. I have a program I''m developing, and multiple
different forms will be opened. For now though, I just have two forms. One is
the main window, and the other sets some preferences like names, and email
addresses.

When someone opens this window, and enters values on this page, I''d like it
to set the values of public variables on the main page.

I''m assuming this can be done, but how?

On the main page, I set a public form2 as 2ndForm = new secondForm

I can access the 2nd form properties from the main page, but not visa-versa.

?????????

Thanks

推荐答案

您在谈论Windows或Web应用程序吗?


使用WebForm应用程序,我们现在使用1页范例来提交和处理表单数据的
。使用Windows窗体应用程序,您只需要将
变量声明为公共范围,并且可以从

其他表单实例访问它们。

您是否注意到,Public变量应该在* first *

表单上声明,然后它们将从第二个表单中获得。


"卡西" <钙*** @ discussions.microsoft.com>在消息中写道

新闻:C4 ********************************** @ microsof t.com ...
Are you talking about a Windows or Web application?

With WebForm applications, we now use a 1 page paradigm for submitting and
processing form data. With Windows Forms applications, you just need to
declare the variables to Public scope and they will be accessible from the
other form instance.
Did you catch that, the Public variables should be declared on the *first*
form, then they will be available from the second form.

"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
是的,我知道这个问题是2周前的其他人提出来的。但是
我需要一些额外的帮助。我有一个正在开发的程序,将会打开多个不同的表单。但就目前而言,我只有两种形式。一个
是主窗口,另一个设置了一些偏好,如姓名和电子邮件地址。

当有人打开此窗口时,输入值页面,我想在主页面上设置公共变量的值。

我假设这可以做到,但是如何?

在主页面上,我设置了一个公共form2作为2ndForm = new secondForm

我可以从主页面访问第二个表单属性,但不是
签证 - 反之亦然。

?????????
谢谢
Yeah, I know this question was asked by someone elselike 2 weeks ago. But
I
need some additional help. I have a program I''m developing, and multiple
different forms will be opened. For now though, I just have two forms. One
is
the main window, and the other sets some preferences like names, and email
addresses.

When someone opens this window, and enters values on this page, I''d like
it
to set the values of public variables on the main page.

I''m assuming this can be done, but how?

On the main page, I set a public form2 as 2ndForm = new secondForm

I can access the 2nd form properties from the main page, but not
visa-versa.

?????????

Thanks



你在说话吗?关于Windows或Web应用程序?


使用WebForm应用程序,我们现在使用1页范例来提交和处理表单数据的
。使用Windows窗体应用程序,您只需要将
变量声明为公共范围,并且可以从

其他表单实例访问它们。

您是否注意到,Public变量应该在* first *

表单上声明,然后它们将从第二个表单中获得。


"卡西" <钙*** @ discussions.microsoft.com>在消息中写道

新闻:C4 ********************************** @ microsof t.com ...
Are you talking about a Windows or Web application?

With WebForm applications, we now use a 1 page paradigm for submitting and
processing form data. With Windows Forms applications, you just need to
declare the variables to Public scope and they will be accessible from the
other form instance.
Did you catch that, the Public variables should be declared on the *first*
form, then they will be available from the second form.

"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
是的,我知道这个问题是2周前的其他人提出来的。但是
我需要一些额外的帮助。我有一个正在开发的程序,将会打开多个不同的表单。但就目前而言,我只有两种形式。一个
是主窗口,另一个设置了一些偏好,如姓名和电子邮件地址。

当有人打开此窗口时,输入值页面,我想在主页面上设置公共变量的值。

我假设这可以做到,但是如何?

在主页面上,我设置了一个公共form2作为2ndForm = new secondForm

我可以从主页面访问第二个表单属性,但不是
签证 - 反之亦然。

?????????
谢谢
Yeah, I know this question was asked by someone elselike 2 weeks ago. But
I
need some additional help. I have a program I''m developing, and multiple
different forms will be opened. For now though, I just have two forms. One
is
the main window, and the other sets some preferences like names, and email
addresses.

When someone opens this window, and enters values on this page, I''d like
it
to set the values of public variables on the main page.

I''m assuming this can be done, but how?

On the main page, I set a public form2 as 2ndForm = new secondForm

I can access the 2nd form properties from the main page, but not
visa-versa.

?????????

Thanks



是的。我正在谈论一个窗体。

网页形式的东西我下来了。


我确实在第一张表格上公开了它们......我以为我需要做的就是

输入类似的东西:


(来自表格2)

form1.person1。 name =" betty"


但是,在Visual Studio中,每当我尝试放置类似的内容时,

强调它说引用非 - 共享成员需要一个对象

引用。


所以...我的假设不正确。


我尝试创建它的引用:


public firstForm as Form1


这使得下划线消失,但在运行时,它会抛出一个

例外:

"对象引用未设置为对象的实例。


所以我不喜欢不知道。

也许我只是不理解?

" Scott M."写道:
Yeah. I''m talking about a windows form.
The web form thing I got down.

I did declare them public on the first form... I thought all I needed to do
was to type something like:

(from form 2)
form1.person1.name = "betty"

however, in Visual Studio whenever I try to put something in like that it
underlines it saying "Reference to a non-shared member requires an object
reference."

so... my assumption was incorrect.

I tried creating a reference to it:

public firstForm as Form1

That makes the underlining go away, but during runtime, it throws an
exception:
"Object reference not set to an instance of an object."

so I don''t know.
Maybe I''m just not understanding?
"Scott M." wrote:
您在谈论Windows或Web应用程序吗?

使用WebForm应用程序,我们现在使用1页范例进行提交和
处理表格数据。使用Windows窗体应用程序,您只需要将变量声明为公共范围,并且可以从
其他窗体实例访问它们。
您是否注意到了,应该声明公共变量* first *
形式,然后它们将从第二种形式提供。

Casey <钙*** @ discussions.microsoft.com>在消息中写道
新闻:C4 ********************************** @ microsof t.com。 ..
Are you talking about a Windows or Web application?

With WebForm applications, we now use a 1 page paradigm for submitting and
processing form data. With Windows Forms applications, you just need to
declare the variables to Public scope and they will be accessible from the
other form instance.
Did you catch that, the Public variables should be declared on the *first*
form, then they will be available from the second form.

"Casey" <Ca***@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
是的,我知道这个问题是2周前的其他人提出的。但是
我需要一些额外的帮助。我有一个正在开发的程序,将会打开多个不同的表单。但就目前而言,我只有两种形式。一个
是主窗口,另一个设置了一些偏好,如姓名和电子邮件地址。

当有人打开此窗口时,输入值页面,我想在主页面上设置公共变量的值。

我假设这可以做到,但是如何?

在主页面上,我设置了一个公共form2作为2ndForm = new secondForm

我可以从主页面访问第二个表单属性,但不是
签证 - 反之亦然。

?????????
谢谢
Yeah, I know this question was asked by someone elselike 2 weeks ago. But
I
need some additional help. I have a program I''m developing, and multiple
different forms will be opened. For now though, I just have two forms. One
is
the main window, and the other sets some preferences like names, and email
addresses.

When someone opens this window, and enters values on this page, I''d like
it
to set the values of public variables on the main page.

I''m assuming this can be done, but how?

On the main page, I set a public form2 as 2ndForm = new secondForm

I can access the 2nd form properties from the main page, but not
visa-versa.

?????????

Thanks




这篇关于在两个表单之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆