- 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.
Edit 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.
Edit 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.Edit 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...Edit 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.
Edit Admin
Yes. Like I said, it's still a huge WTF.