Wajrak wrote:
But you make me wonder with one thing you wrote and if you don't mind (and I think you don't, because last time you spent a lot of your time after answering my question explaining some other things to me), it was: "never, never use such names, rename auto-generated names to something semantic" This is the first time when someone suggested this to me so I'm quite surprised. If you could let me know why? It would be my pleasure. Again, Thank you for your time.
Check out Microsoft naming conventions, they are pretty good. Underscore ('_') is not allowed, as well as numerals ("label1", "textBox2"). Isn't it logical? By the way, check out FxCop; it won't justify violation of naming conventions; and this tool is very useful:
http://en.wikipedia.org/wiki/FxCop[
^],
http://code.msdn.microsoft.com/codeanalysis[
^],
http://msdn2.microsoft.com/en-us/library/bb429476.aspx[
^].Also, I noticed extreme idiocy (this time, real idiocy), when in real-life application people use the string "class" in the name of class, "app" or "application" in the name of *.EXE file, and so one, so "label1" for a label is stupid enough. So, why auto-generated code violates Microsoft naming conventions?
I think the answer is obvious. The Designer simply cannot do better, is it cannot "know" the semantics. Consider auto-generated names as an approximation #0 and always rename auto-generated names to something semantically sensitive.
However, the root of the problem is somewhat deeper. People usually heavily abuse the Designer and almost never under-use it. Do you see how ineffective would be the design when a number of similar labels, buttons and text boxes are put on the form using the Designer? This is a poor manual are repetitive work. No reuse at all. No supportability. Yes, many people act under the impression that the Designer "automates" their work. Why? I think this is apparent:
The Force has a strong influence on the weak minded.
This is the problem.
So, the really effective UI design should always be done in code. Similar controls can be put in some array or any collection, so they can be processed in a uniform manner, in loops, and the names — importantly! — can be put into *.resx resource, so the UI will be globalized. No absolute positioning should be used, everything should be docked, so the combination of
Dock
and
Padding
properties should make the design, which is also globalized, because it does not make any strong assumption on the sizes of the UI strings. And, one important items is (but many people told me they disagree): in most cases, Designer's manner of adding event handler is no good. It is based on old syntax. It's much better to do using
anonymous methods.
[EDIT]
Please see my past answers where I advocate anonymous methods for event handlers:
how to call keydown event on particular button click[
^],
[Solved] How to add Event for C# Control[
^].
See also some other answers on events:
A question about usercontrols, nested controls and encapsulation.[
^],
WPF : How to Use Event in Custom Control[
^],
Since we have multicast delegates, why do we need events?[
^],
c# networking windows form[
^],
Calling an Event as a Function in C++ CLI[
^].
[END EDIT]
In practice, here is what I do it the UI is going to be complex enough: I add main menu and
StatusBar
, and then I add a hierarchy of panels, docked in each other, is some rare cases, with
Splitter
. Then I give them all semantic name. The Visual Studio refactorization engine makes it quite easy. Some times, I add something else, not much. And then, I add everything else in code. In code, I add uniform
Padding
, according to some algorithm. To change the look, I need to change only one or two explicitly defined constants. (And what the user of the Designer-based approach would do? apparently, revisiting all controls, manually!) And, finally, I add all event handlers using "+=". In code. My life is easy, but those who do it all in the Designer suffer a lot. Why? "Obi Wan taught you well."
Good luck,
—SA