Windows控件启用/禁用跟踪 [英] Windows controls enable/disable tracking

查看:104
本文介绍了Windows控件启用/禁用跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一段时间的winforms了,但我还没有找到一种合适的方法来跟踪在特定时间根据特定条件哪些控件处于活动状态,例如,所有文本框都为非null还是白色空间中,已选择了适当的选项,在这种情况下,请启用确定"按钮.

我开玩笑地为每个控件编写一个枚举,并为每个控件编写一个具有bool属性的类,例如,当发生文本框文本更改事件时,我用控件名称和值调用了一个方法,然后该方法将控件的bool属性,并在给定哪些控件有效的情况下检查哪些控件现在处于活动状态.

我的问题是,我描述的系统非常混乱,任何人都可以描述一种更好的方法,或者可能知道一个站点,它解释了一种实现此目的的好方法,我已经进行了互联网搜索并且可以找到非常有用的信息.小.

任何人都可以提供帮助,谢谢.

I have been writing winforms for a while now and I still haven''t worked out a decent way of tracking what controls are active at a given time depending on particular conditions, for example, are all text boxes non null or white space, has the appropriate options been selected, in which case enable the OK button.

I toyed around with writing a enumeration for each control and a class with bool attributes for each respective control and when a text box text changed event occurs for example, I called a single method with the control name and value, this method would then set the bool attribute for the control and check to see what controls are now active, given what controls are valid.

My question is, the system I described turned out to be quite messy, can anyone describe a better way, or perhaps know of a site which explains a good way to do this, I have already done a search of the internet and can find very little.

Anyone able to assist please, thanks.

推荐答案

我的看法是,您有几种选择,但都不是整洁的:

1)通过事件进行操作的方式
2)重载控件并为其提供IsActive属性等,并使每个控件调用包含的控件(如果有)以获取您感兴趣的控件
3)编写一个采用根控件并递归遍历包含在其中的子控件树的方法.例如,如果单击文本框,则确定其状态.

以上所有内容都以不同的方式凌乱,我个人会在winforms中获得3.

您可能还值得考虑从问题中退后一步,并问为什么您需要以这种方式解决此问题?可能有不同的架构模式更适合您的问题,例如MVC或M-V-VM,其中对象模型决定除非设置值才能完成某事,否则ViewModel可能会决定这一点. M-V-VM在WPF上可以很好地工作,但在Winforms上我不太确定.当然,这一切都取决于您要做什么,就像YMMV一样,但是您所描述的肯定是我过去看过的一种方法.希望这会有所帮助!
The way I see it you have several options, none of them neat:

1) The way you did it, with events
2) Overload controls and give them IsActive properties etc, and make each control call contained controls (if any) to get the ones you are interested in
3) Write a single method which takes a root control and traverses recursively the child control tree contained within it. If you hit a text box for example, you determine its status.

All the above are messy in different ways, personally I''d go for 3 in winforms.

You might also be worth considering taking a step back from the problem and ask why do you need to solve this problem this way? It is possible that a different architectural pattern is more suited to your problem, such as MVC or M-V-VM where the object model decides that something can''t be done unless a value is set, or ViewModel might decide this. M-V-VM works well with WPF but I am less sure of it with Winforms. Of course it all depends what you are trying to do, as ever YMMV ,but the you described is certainly one way I''ve seen it done in the past. Hope this helps!


这篇关于Windows控件启用/禁用跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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