为另一个类中的一个类中的事件指定空值 [英] Assigning a null value to an event in one class from another class

查看:90
本文介绍了为另一个类中的一个类中的事件指定空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的程序允许用户通过某些控件调整其计算引擎:单选按钮,复选框等。问题是,根据这些设置,会发生适当的事件这将提高我的程序性能(通过禁用某些动态GUI更新)或减慢它(动态GUI控件的更新)。

要禁用这些GUI组件,必须将事件指定为null。

如何从其他类中执行此操作?

展开 | 选择 | Wrap | 行号

解决方案

我应该将控件.Checked参数作为公共静态并在Class 1中访问它们,如Class2.radBut1.Checked?

否。永远不要公开访问控件本身。

制作有能力做到这一点的属性。

展开 | 选择 | Wrap | 行号

我会有很多控件,如果我添加方法来检查它们是否是Checked,它会添加许多额外的代码。有更好的方法吗?


Hello guys,
My program would allow a user to tweak its calculations engine via certain controls: radio buttons, check boxes etc. The problem is, based on such settings, appropriate events would take place that would either improve my programs performance (by disabling certain dynamic GUI updates) or slow it down (dynamic GUI control''s updates).
To disable those GUI components, an event has to be assigned to null.
How can I do that from another class?

Expand|Select|Wrap|Line Numbers

解决方案

Should I make the controls .Checked parameters as public static and access them in Class 1, like Class2.radBut1.Checked ?


No. Never give public access to the controls themselves.
Make properties that have the power to do that.

Expand|Select|Wrap|Line Numbers


I would have quite a lot of controls, if i add method to check if they are Checked or not, it would add lots of extra code. Is there a better way?


这篇关于为另一个类中的一个类中的事件指定空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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