Re: General Coding Question
Welcome to the forums. :wave:
That is code generated by the Forms Designer.
Where did you get this project?
Re: General Coding Question
If you look at that ton of code, you will see a few items that should look familiar: All the controls are declared in that section, and all the controls are instantiated in that section. Both steps could have been done at once, but for whatever reason, the declaration and creation are separate, thereby doubling the size.
What else is in there? You should see sections for each control that sets all the properties for the control, and somewhere you will see a section that adds the control either to the form control collection, or to the control collection of whatever control contains it (such as a panel, groupbox, etc.)
Look it over and the patters within it will become obvious.
Re: General Coding Question
These are student sample programs from textbook - I know they are Windows Forms Designer Code - But there is so much of it - I cant make sense of it. So this is all the code already written in the sample program? Why so much? thanks
Re: General Coding Question
Hey,
The Windows Form Designer Code region, is simply the code that is generated each time you change something on the design surface.
For instance, if you add a button, and change the text to "hello" then the code that is necessary to do this is added within this region.
There is so much code, because dragging and dropping a button onto the form surface requires a lot of work. For instance, you need to instantiate the button, you need to set it's size, it's location, it's colour, it's text, you need to hook up any event handlers that are created for the button, etc, etc. All of these things are done easily through the designer simply by clicking on, and changing the different properties. If you were actually to do all of those things by hand, then you would see that it does require a lot of code to do it.
With the advent of .Net Framework 2.0, partial classes were introduced. You should find that all the Windows Forms Designer code is placed in one partial class, and another partial class is created in which the developer code is normally written, i.e. the Form Load event, Button Click events etc. Then, when the program is compiled, these partial classes are brought together and all the code executes.
Bottom line, you don't really need to worry about the code that is in that region, and that is why it is hidden away in a partial class out of sight. Very rarely, if at all, do you need to change something in there. All changes are handled through the designer for you.
Hope that makes sense!!
Gary
Re: General Coding Question
Gary touched on the pint - Partial Classes. If this project was originally written in VB 2008 then there wouldnt be any "Windows Designer Generated Code". It would be linked in a partial class instead and not visible in your code unless you clicked the "Show all files" button. So perhaps this project was written in 2002/2003 and upgraded?
Re: General Coding Question
The code can be there, even in 2005-2008. Partial classes generally hide it all away from the user, but there are still instances where it is not hidden in a partial class (some code generators). Still, it can generally be ignored.