- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
I have no experience with Windows.Forms, but I know that when using the Qt framework, there is a subtle difference between disabling a widget vs disabling all its children: in the first case the (parent) widget no longer receives keyboard event while in the latter it does.
Admin
Admin
Honestly, I prefer the second scenario. I really do. One is a lazy screwup by an idiot. The other is a masterfully crafted mystery of misery mangled magnificently by a malevolent mangler for the future misfortune of miserable maintainers.
Admin
I'll add: if your variables are not in English or something that can be construed as such, you have another big problem. And that's from somebody whose first language is not English.
Admin
What makes me think it might be the second scenario is that the code doesn't check if the control is a button, so this might be how the programmer disables everything except buttons. That would be a reasonable UI - if you have a bunch of input fields and then Start and Stop buttons, you would want the Stop button to stay enabled.
Everything else about it is a huge WTF, of course.
Admin
Surely then it'd be eazier to do if (C.GetType() != typeof(System.Windows.Forms.Button)).
Admin
I've done something similar to this once or twice, written more efficiently and more clearly of course, but the point was to disable all the input controls while leaving informational controls (labels, images, and a textbox) enabled. Generally it's better to split such controls off into their own panels or groupboxes, but occasionally that wasn't practical and I have to jump in an do it manually.
Admin
Former chief on IT here. ounterpoint: One of my coding rules was naming the variables in spanish or recognizable spanish abbreviations, precisely to make it obvious that they were our applications variables and not language keywords, usually in english. No Ñs or accents allowed, though.
Admin
"Bloquear" in Spanish means "to block" and you can translate it as "to disable" so the semantic of the
bolBloquearvariable is inverted. It should have been calledbolPermitirorbolHabilitaror something like that. And why did they bother giving the iterators different namesC,C1andC2? That implies they either copy-pasted the block and then renamed the variable or they just wrote every block from scratch. Hard to tell at this point which is worse.Admin
Careful, there's a key difference between
GetType()==andis, that difference being the behavior with derived classes. Now, without more data to know which behavior is desirable...Admin
Most likely because there are some controls in the panel that shouldn't be disabled (static labels, the Cancel button, etc.) so you mustn't just blindly disable all controls. (Yes, that's already been said, but @Dragnslcr forgot non-button other things that you might not want to disable.)
Admin
Isn't there some mechanism where you can group your controls inside a container and when you disable that container it disables all the controls? I'm sure I remember that from my vb6 days (or <fieldset> for web folks)
Admin
No behavior is desirable in this context. The proper way to do this is to reference each control by its name so as to ensure any change in value is done on a deliberately chosen element. Yes, it's more code to write but it is much, much more maintainable.
Admin
I too have enabled / disabled controls by type. It was messy, but real life often is messy, and code reflects that.
We strive for clarity and clean lines of separation, but If real life wasn't so messy, we'd have far fewer big projects coming in 3 years late, and at triple the expected cost.
Admin
Yes. Like I said, it's still a huge WTF.
Admin
I think there is a misunderstanding how WinForms work:
Disabling the parent control is NOT the same as disabling all children.
The reason is simple, the disable state themes the control differently and for group boxes you actually don't won't the visual change, because it looks ugly.
Now the implementation is sloppy and the copy&past makes it obvious that there should be instead be a filter method and then you end up with one foreach per group with controls filtered a simple boolean condition to change Enabled. But Jaloopa already pointed that out.
Admin
is keyword would not be the same since is allows for matching on a subclass while comparing Type objects for equality does not (you'd want Type.IsAssignableFrom to match the behavior of is).
Admin
I was dealing with a case recently where a requirements change meant that a single checkbox in the groupbox needed to remain enabled when everything else was disabled. (Well, surely that checkbox doesn't belong in the groupbox. But alas, it does.) Can we just put the checkbox on top of the groupbox? No, because that breaks the tab ordering. So we have to do the whole thing about disabling everything in the groupbox except the one checkbox. It's not hard, just annoying because it feels like fighting against the framework. But at the same time, no one has been able to come up with a better way to structure the layout.
Admin
The lawyers have a saying that "Bad cases make bad law". Meaning ugly convoluted crime or litigation situations produce court decisions that are ugly and convoluted whose precedent will have hard-to-predict but mostly bad results on future court cases.
In IT we have "Bad business processes make bad code"
Admin
I maintain a rather sizable chunk of code which has an unfortunate ancestry with a mix of failed copypasta, multiple non-English-speaking authors, and rAndOM cAPitaLizaTIOn. For example:
this.TryToBingdingControl((Control) ...)
If this code rings a bell (groan), I sympathize.
Admin
购买真假护照(微信:jerryroy1000)、驾驶证、身份证、在线购买克隆信用卡、雅思、托福、VISA, IDP、GMAT、ESOL、NEBOSH、文凭在线办理,(WeChat: jerryroy1000)
我们提供优质可靠的在线证件办理服务。我们致力于让每个人都能更轻松地获取护照、驾驶证、身份证等证件。让我们成为您的解决方案。
我们重视客户的质量、信任和便捷性。我们的目标是以优惠的价格提供有效的证件,并让整个过程轻松无忧。
微信:jerryroy1000
WhatsApp联系方式:+1(928)8003482
邮箱:[email protected] WeChat: jerryroy1000
在线购买真假护照,购买中国护照(微信:jerryroy1000),购买台湾护照,购买香港护照,购买中国身份证,购买中国驾照,购买中华人民共和国旅行证件,购买中国签证,在中国购买托福、雅思、托业考试成绩。购买人民币假币, 无需考试即可购买 Celpip 证书 WhatsApp:+1(928)8003482 购买中国旅行证件中华人民共和国
在线购买身份证、购买真正的加拿大身份证、(微信:jerryroy1000 )购买加拿大永久居民身份、购买加拿大居民许可证、申请加拿大公民证书、购买加拿大身份证、获得政府身份证、购买新奇身份证、购买真实身份证明文件。
我们以最优价格和卓越品质提供各类签证、旅行证件和护照。我们办理小国护照、多国护照、东南亚出入境协助、护照激活、快速入籍和第二身份规划,为您提供多种选择。
在线购买护照(微信:jerryroy1000),购买美国护照、中国护照、香港护照、台湾护照、外交护照、购买中华人民共和国旅行证件 WhatsApp:+1(928)8003482 购买假币。(微信:jerryroy1000)购买假美元(USD)、购买假人民币(RMB)、购买假人民币(CNY)、购买假人民币/RMB、购买假币(CNY)、购买假人民币/RMB、购买假加元(CAD)、购买假澳元(AUD)(WHATSAPP:+1(928)8003482)购买假英镑(GBP)、购买假欧元(EUR)、购买假港元($HK)。购买高品质、未被检测的纸币。购买中国旅行证件中华人民共和国, 购买假美元/澳元/加元/人民币/欧元/人民币,购买假欧元钞票,购买假澳元,购买假加拿大元,购买假美元,在线购买假人民币,购买假人民币
购买真实护照、签证、驾照、GMAT、雅思、PLAB 1&2证书,购买雅思、GRE、托业、托福、PET、FCE、CAE、CPE、BEC、YLE、KET、BULA TS、ILEC、ICFE(微信:jerryroy1000) 保证,使用我们的证件绝对不会有问题。收到您的订单后