| | |
Is my understanding of code generation in WinForm apps correct?
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 80
Reputation:
Solved Threads: 0
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?
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?
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.
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.
![]() |
Other Threads in the C# Forum
- Previous Thread: Invalid URI: The Uri string is too long
- Next Thread: Why use delegates?
| Thread Tools | Search this Thread |
.net access algorithm alignment app array barchart bitmap box broadcast c# c#gridviewcolumn cast check checkbox client combobox communication control conversion csharp custom database datagrid datagridview dataset datatable datetime degrees development draganddrop drawing elevated encryption enum excel file focus form format forms function gdi+ hospitalmanagementsystem httpwebrequest image index input install java label list listbox localization login mandelbrot math messagebox mouseclick mysql operator path photoshop picturebox pixelinversion plotting pointer post programming radians read regex remote remoting richtextbox server sleep socket sql statistics stream string stringformatting sun table text textbox thread time timer update usercontrol validation visualstudio webbrowser whileloop windows winforms wpf xml






