在另一个窗体中运行方法? [英] Run method in another windows form?

查看:68
本文介绍了在另一个窗体中运行方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了很长时间的asp.net,因为我已经忘记了

windows编程,所以请原谅这个(貌似)基本问题。


我有一个表格A,然后打开表格B.我在表格B之后做了一些东西,我点击了一个关闭按钮。我想在表单A上运行一个方法,因为我接近表格B.我不需要传回数据(虽然我想知道

这是怎么回事完成),只需在表单B上运行一个刷新类型方法。


我已陷入代理和代码示例,这一定很容易

吧?


谢谢

I''ve been doing asp.net for so long now that I have forgotten about
windows form programming so excuse this (seemingly) basic question.

I have a form A which then opens up form B. I do stuff on form B after
which I hit a close button. I want to run a method on form A as I
close form B. I don''t need to pass data back (though I like to know
how this is done), just run a refresh type method back on form B.

I''ve got bogged down in delegates and code samples, this must be easy
right?

thanks

推荐答案

>我有一个表单A,然后打开表单B.我在
> I have a form A which then opens up form B. I do stuff on form B after
之后在表单B上执行了操作,我点击了一个关闭按钮。我希望在表单A上运行一个方法,因为我关闭表单B.我不需要传回数据(虽然我想知道
如何完成),只需运行刷新类型方法回到表格B。
which I hit a close button. I want to run a method on form A as I
close form B. I don''t need to pass data back (though I like to know
how this is done), just run a refresh type method back on form B.




我想你真的想要访问表格B.如果你阻止

表单实际关闭,并简单地强制它隐藏,资源

仍然可用,你可以得到你的信息。


此外,如果你使用表格B显示ShowDialog,这一步将自动为您处理
。表格没有完整处理,反过来可以重新显示



然后你可以从属性中获取信息。


-

贾斯汀罗杰斯

DigiTec Web Consultants,LLC。

博客: http://weblogs.asp.net/justin_rogers


感谢您的回复,但在这种情况下,我不需要从另一种形式访问

的数据。表格B更新数据存储区,然后关闭,然后我只需要表格A获取最新数据。我有一个表格A的方法对这个做b / b
,我只是想办法生成一个运行

方法的事件。

Thanks for the reply, but in this case I don''t need access to data from
the other form. Form B updates a datastore, then closes, then I just
want Form A to "Obtain the latest data". I have a method in form A do
to this, I just can''t figure out a way to generate an event to run the
method.


那么,让我们解决这个问题:


公共类FormA:表格{

private void DoIt(){

FormB b = new FormB();

b.DataUpdated + = new EventHandler(DataStore_Updated);

b.Show();

}


//为活动设一个处理程序

}


公共类FormB:表格{

公共事件EventHandler DataUpdated;


private void OnDataUpdated(EventArgs e){

if(DataUpdated!= null)

DataUpdated(this,e);

}

}


//关闭时只需调用OnDataUpdated

}


另一个选项是事件业务层...如果你正在执行

但是,这可能导致多个操作。

的替代方案是添加一个事务模型,以便在开始更新

时获得一个令牌,并使用它来结束更新,然后事件

更新了数据存储。

-

Justin Rogers

DigiTec Web Consultants,LLC。

博客: http://weblogs.asp.net/justin_rogers


< ri ************ @ orcon.net.nz>在消息中写道

新闻:10 ********************** @ c13g2000cwb.googlegr oups.com ...
Well, let''s fix that up then:

public class FormA : Form {
private void DoIt() {
FormB b = new FormB();
b.DataUpdated += new EventHandler(DataStore_Updated);
b.Show();
}

// Have a handler for the event
}

public class FormB: Form {
public event EventHandler DataUpdated;

private void OnDataUpdated(EventArgs e) {
if ( DataUpdated != null )
DataUpdated(this, e);
}
}

// Just call OnDataUpdated when you are closing
}

Another option is an eventing business layer... If you are performing
multiple actions though, this can result in more than a single call. The
alternative is to add a transactional model so that you get a token when
you start updating, and you use that to end your update, then the event
that the data store is updated is fired.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

<ri************@orcon.net.nz> wrote in message
news:10**********************@c13g2000cwb.googlegr oups.com...
感谢您的回复,但在这种情况下,我不需要从其他表单访问数据。表格B更新数据存储,然后关闭,然后我只是想要表格A获取最新数据。我有一个表格A的方法做到这个,我只是想办法生成一个事件来运行
方法。
Thanks for the reply, but in this case I don''t need access to data from
the other form. Form B updates a datastore, then closes, then I just
want Form A to "Obtain the latest data". I have a method in form A do
to this, I just can''t figure out a way to generate an event to run the
method.



这篇关于在另一个窗体中运行方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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