C# forms

  • Thread starter Thread starter Joy Maitland
  • Start date Start date
I saw in a C# project, there is alot of form components .cs files.

http://www.oniva.com/upload/1356/config.jpg

Are those auto generated by form designer?

Most likely. They can be coded by hand, if you like doing lots of work.
How can I call those forms from C# code?

SomeFormClass myForm = new SomeFormClass();

myForm.Show();
those file with a green C# icon are manually coded source file?

The icon displayed in the Solution Explorer window is based on an
examination of the file that VS performs. If it finds a class inside the
file that derives from Form, then it displays the form icon. If it finds one
derived from UserControl, it displays the UserControl icon. If it finds one
derived from one of several control classes, like Panel, TextBox, etc., then
it displays the component icon. There may be a few other types as well, but
ultimately, if it finds none of these types of classes in the file then it
displays the plain old "green" class icon.
 
Most likely. They can be coded by hand, if you like doing lots of work.


SomeFormClass myForm = new SomeFormClass();

myForm.Show();


The icon displayed in the Solution Explorer window is based on an
examination of the file that VS performs. If it finds a class inside the
file that derives from Form, then it displays the form icon. If it finds one
derived from UserControl, it displays the UserControl icon. If it finds one
derived from one of several control classes, like Panel, TextBox, etc., then
it displays the component icon. There may be a few other types as well, but
ultimately, if it finds none of these types of classes in the file then it
displays the plain old "green" class icon.

how can i difference those files that's auto-generated by Visual
Studio and those manually coded in C# project?
 
how can i difference those files that's auto-generated by Visual
Studio and those manually coded in C# project?

You can't, other than perhaps by comments that Visual Studio puts in the
files it auto-generates. Why would you want to?
 
You can't, other than perhaps by comments that Visual Studio puts in the
files it auto-generates. Why would you want to?

if it's auto generated, then i don't need to read the code, then i can
concenrate on the reading the manually created source code.

since the C# application has alot of source files, and I have very
limited C# skills.

BTW, does the form / component files automatically opens the form
designer? when i view those files, it does not show the source code??

Also, if i code the form manually, and then use form designer that
will mess up the form / mess up the code? that happen alot when I
using some designer like HTML or Java Swing where the code will mess
up when use manually edit and then designer together.
 
Joy Maitland said:
if it's auto generated, then i don't need to read the code, then i can
concenrate on the reading the manually created source code.

since the C# application has alot of source files, and I have very
limited C# skills.

BTW, does the form / component files automatically opens the form
designer? when i view those files, it does not show the source code??

Also, if i code the form manually, and then use form designer that
will mess up the form / mess up the code? that happen alot when I
using some designer like HTML or Java Swing where the code will mess
up when use manually edit and then designer together.


Click the plus sign near one of the UI files, such as ConfigureForm.cs. You
should see ConfigureForm.Designer.cs. Both files together make the form.
Alternatively if you rightclick on the form icon, you can select "Open
Designer" or "Open Code".

Visual Studio has been better than some of the Java UI development
environments that I have used, but there can be times when things get messed
up.
 
if it's auto generated, then i don't need to read the code, then i can
concenrate on the reading the manually created source code.

since the C# application has alot of source files, and I have very
limited C# skills.

There are very few .cs files that are 100% generated by the IDE. For forms,
the IDE only generates the code necessary to reflect the controls that you
place on the form in Design mode. All other code in the form is written by
the programmer. So you'll still have to read the form files, even though
they're partially auto-generated. The good part is that almost all of the
auto-generated code is placed in the related .Designer.cs file.
 
There are very few .cs files that are 100% generated by the IDE. For forms,
the IDE only generates the code necessary to reflect the controls that you
place on the form in Design mode. All other code in the form is written by
the programmer. So you'll still have to read the form files, even though
they're partially auto-generated. The good part is that almost all of the
auto-generated code is placed in the related .Designer.cs file.

you said "The good part is that almost all of the auto-generated code
is placed in the related .Designer.cs file. "

in the C# project i only see .cs file, i don't seem to see any file
with .Designer extension, what is .Designer files?
 
you said "The good part is that almost all of the auto-generated code
is placed in the related .Designer.cs file. "

in the C# project i only see .cs file, i don't seem to see any file
with .Designer extension, what is .Designer files?

That statement applies only to code created with Visual Studio 2005 or
later. It creates a separate code file for its auto-generated code and uses
the "partial" keyword to split code between these files. If the solution
you're working with was originally developed with VS 2002 (Framework 1.0) or
2003 (Framework 1.1) then all the auto-generated code will be in the
<form>.cs file, usually inside a region named "Windows Form Designer
generated code" or something like that.

Look at the screenshot you linked to in your first post. Do you see all
those + signs in the tree in Solution explorer next to forms and user
controls? If you expand those nodes you should see the .Designer.cs files.
If you don't (perhaps there's only a .resx file) then perhaps you have an
older project where this separate file was not created.
 
I saw in a C# project, there is alot of form components .cs files.

http://www.oniva.com/upload/1356/config.jpg

Are those auto generated by form designer?  How can I call those forms
from C# code? those file with a green C# icon are manually coded
source file?  

I've read the comments and my only comment is make sure you backup all
your project folder before you remove or play with any of the
autogenerated forms, including excluding them from the project, etc.
You will find quickly that sometimes you accidentally delete the wrong
file or line and it is impossible to reincorporate it back into the
project. I'm sure experienced guys will tell you how to
reincorporate, but I could not do it in several instances and simply
had to revert back to my old saved project and start over.

RL
 
There are very few .cs files that are 100% generated by the IDE. For forms,
the IDE only generates the code necessary to reflect the controls that you
place on the form in Design mode. All other code in the form is written by
the programmer. So you'll still have to read the form files, even though
they're partially auto-generated. The good part is that almost all of the
auto-generated code is placed in the related .Designer.cs file.

I saw there is

RFIDTracer.cs
RFIDTracer.designer.cs
RFIDTracer.resx

RFIDTracer.cs --> I think this file contain manually written code??
RFIDTracer.designer.cs --> I thin kthis file contain IDE generated GUI
code??
 
I saw there is

RFIDTracer.cs
RFIDTracer.designer.cs
RFIDTracer.resx

RFIDTracer.cs --> I think this file contain manually written code??
RFIDTracer.designer.cs --> I thin kthis file contain IDE generated GUI
code??

Exactly. This is the case with forms, user controls, and some other things
like services and maybe components. Not every file that Visual Studio
auto-generates has "Designer" in its name, though, but I believe any file
that has code (any code, not just GUI code) in it does.
 
Back
Top