473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Is my understanding of code generation in WinForm apps correct?

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?
Feb 26 '09 #1
1 1200
tlhintoq
3,525 Expert 2GB
Not a bad start at all. A couple things to keep in mind...

While everyone will tell you that global variables are the evil devil spawn that will destroy the known universe... They are sometimes incredibly practical. Any public property defined in Program.cs will be available to all of the children of Program which would be all the forms and custom controls. I use a PrivlegesObject class in the Program.cs to hold all the user priveleges (can they edit the configuration, permission to exit the application and so on). This way any form, any class can check the Program.Priveleges.ExitApp property to see if the user is allowed to do so.

Program.cs contains the one and only Main() method that really is the practical start of your application. The Main() method then launches Form1 or MyStartupWizardForm or whatever form you want to have be the startup form. By default it is Form1, but it doesn't have to be. You can have a working program that launches Form1, but you can work on an upgrade that will launch Form101 when you have the upgrade done. Just change which form is launched in the Program.cs

Program.cs in my case also contains the code to make sure my applications are single instance only. This is also where I have a splash screen launch from. This way the user gets a splash screen right away no matter what. If your Form1 is going to take 10 seconds to read information and set up the user isn't left wondering if the application launched or not, hung or not...

I think of Form1.cs as the logic of Form1 and Form1.Designer.cs as the UI of the Form. If its for looks then it tends to go into the Designer. If it is for behavior then it goes in Form1.cs.
* - Control creation goes in the designer.
* - Event response goes into the Form1.cs -
But this is a really loose way of looking at it. Form1.cs can very easily create a new control and place it on the form programmatically.

Yes you can edit the Dispose() method. But making changes INSIDE the region of automatically created code can be funky. This is why the Dispose() method is outside of the generated code region.
Expand|Select|Wrap|Line Numbers
  1.         protected override void Dispose(bool disposing)
  2.         {
  3.             if (disposing && (components != null))
  4.             {
  5.                 components.Dispose();
  6.             }
  7.             base.Dispose(disposing);
  8.         }
  9.  
  10. #region Windows Form Designer generated code
  11. // .... generated code for the controls
  12. #endregion
Feb 26 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Marty McDonald | last post by:
If I invoke a web service, and it throws an exception, I can see the exception if the client app is a .Net app. However, if the client app is not a .Net app, I only receive the HTTP 500 error. I...
3
by: jdionne | last post by:
I have a WInform app that runs a DTS. When I developed it on the SQL box and executed it, it ran fine. I used the Trusted connection parameter for the DTS. I don't want to use passwords. I...
15
by: tadpole | last post by:
Well, it's been a year since I jumped from C/C++ and ModPerl to Visual Studio 2003 and C#. Frankly, I'm disappointed with it. There are a lot of little annoying bugs with the IDE that just...
8
by: Sunil Menon | last post by:
Dear All, We are developing applications in ASP.Net...in one of our applications we would like to use a GridControl...we have tried to use a Server-Side Grid control but found the speed to be an...
7
by: Dean Slindee | last post by:
I would like to hear some practical comments about how to decide whether a new application becomes a Winform vs a Webform application. Would you say that every app should be, by default, a Winform...
14
by: helpful sql | last post by:
Hi all, Are there any good Sql code generation tools out there in the market? If not can you please give me tips or sample code for creating one? I need to automate code generation for data...
11
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
14
by: Monty | last post by:
Hello, I have created a solution which has both a web UI and a winform UI, the latter is just for administrators. The Web UI (a Web Application Project) and the winform project both...
0
by: Peter Morris | last post by:
When I compile a WinForm app I get the following warning: The file 'C:\Data\CustomerProjects\Inteevo\Projects\AlterEgo\AlterEgo\WizardStepControls\SceneSettingsStepControl.cs' does not support...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.