views:

511

answers:

1

Hi,
can you recommend a Visual C# Form Designer tutorial that is targeted at experienced programmers who have at least a basic knowledge of C# but are new to the VS C# Form Designer. At least it shouldn't be targeted at programming newbs, like Introduction to Visual C# 2008 Express Edition (it explains how a comment looks like in C#).

So far I've found C# Programming Tutorial - Programming Winforms in C# on stackoverflow.

Wishlist: ;-)
I'm more interested in focus on the designer itself rather than an explanation of single gui-elements. In other words explaining separation between generated-code, what to not edit manually (visual-c#-designer-responsibility) and on the other hand the parts for which the programmer himself is responsible. So a little more abstract best-practice point of view pointing out some caveats would be great as well.

I would prefer text over video as well, but that's minor.
/Wishlist

Perhaps even a Microsoft reference specific to the Visual c# forms designer (which I seem to have been unable to find) would be helpful.

+2  A: 

The forms designer, as you know, is just a code generator. There's nothing preventing you from editing the code it generates. You can add controls, remove controls, and so forth. Some people use this ability to add and remove controls at runtime.

If you modify the designer-generated code, the designer will pick up your changes and display them in the form. This is why you can take someone else's code in toto and drop it into a new C# project, and it will "just work."

I hope that clears things up. The designer is just a "convenience," especially for things like controls positioning and alignment.

Note that this is a little different than, for example, changing code in a data access object, where the class members must match fields in a database. In that scenario, there is a real chance you can break things if you modify the generated code. This is why partial classes are used in those scenarios. Partial classes allow you to tack on your own code without worrying about breaking the generated code, or the code generator wiping out your code additions.

Robert Harvey
First of all that was indeed helpful, but while I know that it is a code-generator and I *can* edit the generated code (already did that), I'm more interested in how it *should* be used or what possible caveats, problems and best-practices there are. It's like you can program completely without indenting anything, but you shouldn't because of ... And If I'm going to ignore this auto-generated comment /// Required method for Designer support - do not modify /// the contents of this method with the code editor. I want to have good justification for myself why that's fine.
Furthermore see this what I would consider an inconsistency, that I found after playing with the designer for only ~30 mins. http://stackoverflow.com/questions/2549586/visual-c-gui-designer-recommended-way-of-removing-generated-event-handler-codeI don't want the code I've written to get deleted because I'm clueless about these kind of different behaviors.</br>In one sentence: I don't know enough yet to be sure that I can't cut/hurt myself with that tool.
Your justification is that you know what you are doing. If you drag a control onto the form designer surface and then look at the code that's generated in `InitializeComponent()`, you will see the pattern that the forms designer uses to create the code. Note that you have to put code to create the controls in *four* different places to make it work.
Robert Harvey
All that said, I seldom have a need to edit the designer code. The only legitimate reason I can think of for doing this extensively is if I was writing my own tool to generate code for a UI (from fields in a database, perhaps).
Robert Harvey
With respect to your other linked question, if the designer leaves a bit of cruft in my code, I just delete the cruft. Remember, the designer doesn't have authority over the code, you do. The designer is just a helper.
Robert Harvey