Mdi表单和处理程序 [英] Mdi form and Handlers

查看:74
本文介绍了Mdi表单和处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有Mdi在模板上创建的表单.有目录形式,还有添加形式.在添加表单上,有一个声明为shared的事件,该事件在单击按钮时发生,在目录表单上,有此事件的处理程序.我在目录形式的构造函数中订阅它.关闭目录表单后,我将删除处理程序.

为什么在一个目录上处理sub会花费这么多的时间,已经打开了多少? IE.我打开和关闭3次,处理次子3次.

添加和继承自抽象类的目录形式.

如何获得活动处理程序的数量?还是我应该如何转换EventHandlerList以获得计数方法?我试图将其转换为HashTable,但发生错误.

请帮忙!

There is Mdi a form created on a template. There is a directory form, and the adding form. On the adding form there is an event declared as shared, which rises on button click, and on the directory form there is a handler of this event. I subscribe for it in the constructor of a directory form. On closing of a directory form i remove handler.

Why handling sub on a directory works so much time, how many it has been opened? I.e. 3 times I open and close, handling sub exucutes 3 times.

adding and directory forms inherited from abstract classes.

how can i get number of active handlers? or how should i convert EventHandlerList to obtain count method? i tried to convert into HashTable but error occurs.

Please Help!

推荐答案

因为订阅事件处理程序时,它一直保持订阅状态,直到对象被销毁或处理程序被删除为止.就像编辑器中的宏键一样:您只需为该键分配一个宏,然后每次使用该键时,该宏就会被执行.
因此,如果您在构造函数中设置一个处理程序,并在关闭窗体时将其删除,则每次引发该事件时,都会调用该处理程序.


感谢您的时间.但是您能告诉我如何避免重复调用处理程序吗?",您说过因为订阅事件处理程序时,它会一直保持订阅状态,直到对象被销毁或处理程序被删除为止"在我的情况下,removehandler不起作用吗?"


很难说:删除处理程序的代码是什么?为什么说它不起作用"?会发生什么?
Because when you subscribe to an event handler it stays subscribed until the object is destroyed or the handler is removed. It''s like macro key in an editor: you assign a macro to the key once, and every time you use the key, the macro gets executed.
So if you set one handler in your constructor and remove it when you close the form, then every time that the event is raised, the handler will be called.


"thanks for your time. But can you tell me what should i do to avoid handler double calling? as you said "Because when you subscribe to an event handler it stays subscribed until the object is destroyed or the handler is removed" in my case removehandler doesn''t work ?"


Difficult to tell: what is your code for removing the handler? Why do you say "it doesn''t work"? What does happen?


我的回答很简单:不要使用MDI!

现在在某些情况下,这种极为不方便的UI样式会有所帮助.几乎任何人都不愿这样做,并且一开始就被认为是Microsoft的错误.通过使用MDI,您只能吓跑客户.首选仅基于一个主窗口进行设计.作为下一个层次结构,您可以使用制表符界面等.

—SA
My answer is simple: don''t use MDI!

There are now situations where this extremely inconvenient UI style helps. Is it totally discouraged by practically anyone and considered to be a Microsoft mistake in first place. By using MDI you can only scare off your customers. Prefer design based on just one main window. As a next level of hierarchy you can use tabbing interface and more.

—SA


这篇关于Mdi表单和处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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