方法执行前如何运行代码 [英] how to run code before method excution

查看:121
本文介绍了方法执行前如何运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带选项卡的Windows窗体应用程序,如果用户关闭任何选项卡我会问他
如果他是否需要保存数据,请给他选择yes,no,取消
我通过继承该handel onclousing方法的形式来解决了这种情况,但是如果用户按下new按钮,它将以相同的形式显示数据,因此尽管必须先保存数据,但是如果用户按下next,也不会关闭该表单.或以前的版本,如果用户正在使用搜索
并且显示了一个新对象而不保存prevois,因此我想为"NewButton_Click"之类的方法创建属性,该属性检查是否存在未保存的数据(我可以通过parentform(activeform)获得该表单),所以会显示询问用户是否需要保存的信息,如果保存,我会调用以该活动形式进行过保存的保存.

i have tabbed windows forms application , if user close any tab i ask him
if he he need to save data or not , giving him option yes , no , cancel
i managed that situation by inherting from form that handel onclousing method , but if the user press the button new , it will show data in the same form , so the form is not closed although there is data must saved first , also if user press next or previous , alse if user is using search
and a new object is shown without saving the prevois , so i think of creating attribute for methods like "NewButton_Click" that attribute check if there are data unsaved or not in the form (i can get that form by parentform (activeform) )so it will show messege that ask if user need to save or not , if saving i will call save that is ovverrided in that active form

推荐答案

您不能,AFAIK ,请指定在所有点击事件之前调用的方法.您应该将保存的代码(如果需要的话)分解为一个方法,并在需要该方法的所有事件的开头调用THAT.
You can''t, AFAIK, specify a method that is called before all click events. You should factor your save if needed code to a method, and call THAT at the head of all events that need it.


这篇关于方法执行前如何运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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