我试图使用第1页对象调用page1到page2的方法 [英] I am trying to call a method of page1 to page2 using page 1 object

查看:69
本文介绍了我试图使用第1页对象调用page1到page2的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在新的win形式中使用第1页对象调用page1到page2的方法,但问题是该方法的功能是iam调用在page1中正常工作但是进入第2页它不起作用。任何人都可以帮我解决这个问题...... !!

I am trying to call a method of page1 to page2 using page 1 object in a new win form but the problem is the functionality of the method is which iam calling is working fine in page1 but coming into page 2 its not working.can anyone help me out this...!!

推荐答案

几乎可以肯定它是新的胜利形式部分,它提出了这个问题。



如果您的Page1表单有一个名为Foo的方法更新表单:

Almost certainly it's the "new win form" part that is giving the problem.

If your Page1 form has a method Called "Foo" which updates the form:
public void Foo(string text)
   {
   myLabel.Text = text;
   }

如果你从Page1调用它然后它可以工作:

If you call it from Page1 then it works:

Foo("hello");

但要从Page2调用它,您需要访问正在运行的Page1的实际实例,这听起来像你这样做:

But to call it from Page2, you need to access the actual instance of Page1 that is running, and it sounds like you are doing this:

Page1 p1 = new Page1();
p1.Foo("Goodbye");

赢了不行,因为它正在创建一个新的Page1和changign而不是改变你可以看到的实例。它就像一辆汽车:如果你把你的手机放在我的汽车的手套箱里,你不要期望在打开汽车的手套箱时找到它,是吗? :笑:



看看这个:在两种形式之间传递信息,第2部分:儿童到父母 [ ^ ] =它可能会让你更简单。

That won't work, because it is creating a new Page1 and changign that rather than changing the instance you can see. It's like a car: if you put your mobile phone in teh glove box of my car, You don;t expect to find it when you open teh glove box of your car, do you? :laugh:

Have a look at this: Transferring information between two forms, Part 2: Child to Parent[^] = it might make it simpler for you.


这篇关于我试图使用第1页对象调用page1到page2的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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