Is my understanding of code generation in WinForm apps correct?

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 80
Reputation: BobLewiston is an unknown quantity at this point 
Solved Threads: 0
BobLewiston BobLewiston is offline Offline
Junior Poster in Training

Is my understanding of code generation in WinForm apps correct?

 
0
  #1
Feb 26th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Is my understanding of code generation in WinForm apps correct?

 
0
  #2
Feb 26th, 2009
pretty much. Although you can tell it to generate only 1 .cs file with the form generated within it.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Is my understanding of code generation in WinForm apps correct?

 
0
  #3
Feb 26th, 2009
1. program.cs contains the main entry point for the application and segregates and provides a code file for all application related code, such as handling unhandled exceptions or initializing certain classes before the "main" form loads. This is in no way related to the forms as you mentioned.
2. yes, except Application.Exit() terminates the application. this.Close() or setting a modalresult on the form terminates the form and not the application, unless it is the main form in which case the app will terminate.
3. Yes, the dispose method could and should be edited to handle cleanup of instantiated IDisposable members that you have added in the userland .cs file. It is also very handy to edit in the case that you have created a descendant of a "TextBox" control named "UltraTextBox" but you don't have it installed on your toolbox. In this case you would drop on a toolbox, go to the designer file, and change the declaration and instantiation of the member to an UltraTextBox. You also may edit the designer file to change the Z-Order of controls which you can probably do through the UI, but its much easier to do in the designer.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC