我们如何在tabcontrol中的两个标签页的button_click事件上编写代码 [英] how we can write code on button_click event for two tab pages in tabcontrol

查看:112
本文介绍了我们如何在tabcontrol中的两个标签页的button_click事件上编写代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,
我使用了具有3个标签页的标签控件,我想在标签控件之外的3个常用按钮上编写3个标签页的代码.
动作按钮:
1)好->保存数据.
2)取消->取消保存数据.
3)修改->更新数据.

Dear sir,
I have used tab control which have 3 tab pages, I want to write the code for 3 tab pages on 3 common buttons which are outside the tab control.
The action buttons:
1) OK --> to save the data.
2) Cancel--> to cancellation of saving data.
3) Modify -- > to update the data.

推荐答案

那么,这是否意味着您想对这三个按钮使用公共事件处理程序?如果是这样,并且您使用Forms,则可以将click事件连接到同一处理程序.就像这样:

So do you mean that you want to use a common event handler for those three buttons? If that''s true and you use Forms, you can wire the click event to the same handler. So something like:

// for example in constructor
this.btnOk.Click += new EventHandler(CommonEventHanldlerForClick);
this.btnCancel.Click += new EventHandler(CommonEventHanldlerForClick);
this.btnModify.Click += new EventHandler(CommonEventHanldlerForClick);


void CommonEventHanldlerForClick(object sender, EventArgs e) {
   // Code goes here
}



但是,您需要根据发送者参数识别每个按钮.为此,可以使用Tag属性.在每个按钮上定义一个适当的标签,然后在事件处理程序中检查作为发送方的按钮的标签.

但是...我不太明白这样做带来的好处.如果您要这样做是因为每个按钮都有很多通用代码,那么我仍将使用单独的事件处理程序.然后,每个事件处理程序将调用一个公共或多个公共方法来执行实际操作.这些方法可以驻留在window类或其他类(如果适用)上.这样,您就不会将用户界面与逻辑混在一起(同样,如果对通用代码的假设是正确的,则:)).



However, you would need to recognize each button based on the sender parameter. For that, you can use the Tag property. Define a proper Tag on each button and then in the event handler check the tag of the button that is the sender.

But... I don''t quite see the benefit from this. If you want to do this because you have a lot of common code for each button, I would still use a separate event handlers. Each event handler would then call a common or multiple common methods to do the actual operations. These methods can reside on the window class or another class if appropriate. This way you wouldn''t mix the user interface to the logic (again if the assumption about the common code was true :)).


这篇关于我们如何在tabcontrol中的两个标签页的button_click事件上编写代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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