• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Building Windows Applications in C# Visual Studio

I am a college student who is new to building application is Visual Studio. I currently have opened a new windows application project in Visual Studio 2005 and has the bare skeleton structure.

This is what I want to do:

1) Create a class diagram. Automatically generate the code based on the class diagram. I already have the class diagram built in Microsoft Visio 2003. If there is a way to import that into Visual Studio 2005, that would be nice too.

2) Write the necessary code in the main() and in the necessary classes generated by the class diagram.

3) Successfully compile ("Build") and run the program.

My Questions:

1) Strategy of how I should accomplish the above with respect to the empty skeleton structure of the code that currently exists.

2)  An brief explanation of what I should know about the following in the skeleton structure of "Program.cs" main method() i.e.:-
[STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

Thanks.

0
scarface7
Asked:
scarface7
1 Solution
 
gbzhhuCommented:

1)

I am not sure about the compatibility of VS2003 to VS2005 but try to add the existing class diagram to VS2005.  Right click on the project and select add|new item and choose a class diagram from the resulting dialog.  If this doesn't work then create the diagram in VS2005.  The code automatically generated as you add classes, methods, properties etc.

Write whatever your necessary code is.  This is a windows application so a form class will have to be instatiated in the main.  Your app starts when that form is displayed.  You then put controls (buttons, labels etc).  For example you can create a click event for one of the buttons you put on the form, then in that click event you can use your other classes to perform a task (display some info, read a file etc)

2)

Application.EnableVisualStyles();
The above line is to do with how controls are displayed.  This line has no effect on your code, it is for WinXP and later special visual rendering of controls

(From MSDN)
This method enables visual styles for the application. Controls will draw with visual styles if the control and the operating system support it. To have an effect, EnableVisualStyles must be called before creating any controls in the application; typically, EnableVisualStyles is the first line in the Main function. A separate manifest is not required to enable visual styles when calling EnableVisualStyles.

Application.SetCompatibleTextRenderingDefault(false);

(From MSDN blogs)
Certain Windows Forms controls can render their text using either the GDI graphics library, or the newer GDI+ library. This change was made because of performance and localization issues with GDI+. By default, existing controls that support the UseCompatibleTextRendering property are set to true for backwards compatibility, but all new controls in environments such as Visual Studio have this property set to false. Use SetCompatibleTextRenderingDefault when you wish to switch the default text rendering for new controls.

You should never call this method if your Windows Forms code is hosted in another application, such as Internet Explorer. Only call this method in stand-alone Windows Forms applications.

No sample code, since the call is very simple. Just stick this in your Main() method before calling Application.Run(), and you're set.

Application.Run(new Form1());

This line starts your application loading a new instance of form1.  Form1 is your start point, you then access other forms/classes in your app from Form1

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now