应用程序中触发事件时应调用方法 [英] method should be called when an event is fired in the application

查看:88
本文介绍了应用程序中触发事件时应调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我们已经完成了这个项目。但是现在我们想要跟踪用户在应用程序中执行操作/事件时为调试目的而执行的文本文档中的每个事件。跟踪我必须在应用程序中所有表单中的每个事件中调用方法,但这是一个冗长的过程。我想通过编写一个方法来做到这一点,以便在应用程序中执行该方法应该调用的时候。



任何人都可以帮助我。

Hi,

We have done with the project. But now we want to track every event in the text document that user have performed for debugging purpose, when an action/event is performed in application. for tracking I have to call method in every event that is in all the forms in the application, but it is a lengthy procedure. I want to do it by writing a method, so that when ever an action is performed in the application that method should call.

Can any one help me in this.

推荐答案

我觉得这很简单,但我只能用c#做,如果你不介意

1)你必须订阅你想要在它被解雇时处理的表格的哪个事件。表单包含许多可以处理的事件。例如,如果您希望在单击表单时调用方法EventMethod_Click,请在表单的构造函数中编写以下内容:

form1.Click + = new EventHandler(EventMethod_Click);



使用上面的代码,您刚刚订阅了Form的Click事件。因此,只要单击表单,就会调用方法EventMethod_Click。



2)创建一个名为EventMethod_Click的私有void方法,其中包含两个参数object和eventArgs



private void EventMethod_Click(object sender,EventArgs e)

{

//做什么你想要这里

}



我希望能帮助你,抱歉用c#回答。
I think that is simple to do but I can only do that in c#, if you don't mind
1) you have to subscribe to which ever event of the form you want to handle when it's fired. A form has many events that can be handled. for example, if you want a method "EventMethod_Click" to be called any time a form is clicked, write the following in the form's constructor:
form1.Click += new EventHandler(EventMethod_Click);

with the above code, you've just subscribed to the Form's Click event. therefore, any time the form is clicked, the method "EventMethod_Click" will be called.

2) create a private void method named "EventMethod_Click" with two parameters, object and eventArgs

private void EventMethod_Click(object sender, EventArgs e)
{
// Do what ever you want here
}

I hope that helps you, sorry for answering with c#.


这篇关于应用程序中触发事件时应调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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