Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is my understanding of code generation in WinForm apps correct?

Status
Not open for further replies.

thedougster

Programmer
Jan 22, 2009
56
0
0
US
Is my understanding of code generation in WinForm apps correct?

When you create a program that features a single Windows Form using Visual C#'s Windows Form Designer, three source files are created:

1. program.cs, which:
.....a. does some preliminary configuration of the form and then launches it, and <-- couldn't configuration be done transparently upon launching?
.....b. all the user-written, non-form-related stuff.

2. form1.cs, whose generated code contains that part of the form's class that is to be editted by the user, including "empty" methods:
.....a. the constructor, which calls InitializeComponent, which initializes the form, and
.....b. various user-written, event-driven methods, which:
..........1. handle "operation" of the form, and
..........2. call Application.Exit, which terminates execution of the form.

3. form1.designer.cs, whose generated code contains that part of the form's class that is NOT to be editted by the user:
.....a. the Windows Form Designer generated method InitializeComponent, and
.....b. the method Dispose, which disposes of the form. <-- can't this be editted?
 
pretty much.

program.cs could all be done behind the scenes, but then you wouldn't see that there was stuff you could configure.

form1.designer.cs is for the designer, yes, but you can edit it if you need to and are reasonably careful.

it's always annoyed me that given that you need to Dispose() of IDisposable objects that you create there's no mechanism for putting this code in form1.cs instead of form1.designer.cs.

mr s. <;)

 
1. this is where the system should be initialized. if you use IoC containers this is the place to create and populate the container. with asp.net this is similar to Global.asax

2. this is where you put code related to loading values and getting values from the form. you could put logic here, but use some form of an MVC framework to handle the flow.

3. this makes it easier to translate between the GUI form and the code. this file should not be edited as it's regenerated any time you make a change to the GUI (not the code file).

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top