C # is a modern programming language, which is included in Visual Studio. NET 7.0. It simplifies the complexity of C ++ and maintains flexibility. It is easy for people who have learned C ++. Visual
Studio. NET 7.0 beta1 has been released. This article provides some simple development attempts for this version.
Download Sample Code
18 K
1. Create a project
In the File menu of the integrated development environment, select new-> project to open the new project dialog box.
Select Visual C # projects as the project type and Windows application as the template,
Enter the project name hellowindows in name, and enter the saved path in location.
After confirmation, the system automatically generates a program framework for you.
Now let's get familiar with this development environment.
This is our development environment!
Zone A is our toolbox, including support for databases, components, form controls, etc. We can select and add it to form. If you cannot find toolbox, select toolbox in the menu view to open it.
Zone B is our design workspace (including the design of the interface and code). The figure shows the main window of the application we just created: form1.
Zone C is equivalent to the workspace in vc6: Solution Explorer can be regarded as the previous FileView. resourceview and classview must be familiar to everyone. See Solution
Is form1.cs in explorer? This is the C # file corresponding to form1. Double-click it to design the form1 interface. Right-click form1.cs and choose View from the pop-up menu.
Code to view the corresponding code.
Zone D is the attribute window: similar to the attribute window in the resource editor in vc6, it is more powerful, you can directly modify the attributes of components such as buttons and list boxes on the screen, such as text and background color.
The next task is to create a dialog box and add a menu to open this dialog box.
2. Add a new form: Dialog Box
Select project> Add windows form. In the displayed dialog box, set category to local project items and template to Windows.
Form, enter the file name in name: aboutdlg. CS, and confirm. The new form appears in the workspace. In the Properties dialog box of Area D, Modify text to "about" and select backcolor to light blue. You can also change other attributes.
Next, we open toolbox, select the label in win forms, and draw it in the form. In the Properties dialog box, Modify text to "VC knowledge base. Welcome! Http://www.vckbase.com ", we are at win
Add a button in forms and change text to "OK ".
Now, we have designed the dialog box interface, but how can we close the dialog box when the user presses the OK button?
Double-click "OK". The system will automatically add the processing code for the button. In this case, we add the close () function to close the code, as shown below:
Protected void button#click (Object sender, system. eventargs E) { Close (); // This is an added sentence.
} |
The dialog box has been completed. Next we need to add a menu for the main window. When you select the menu, we will pop up the "about dialog box". Let's continue...
3. Add a menu for the Main Window
In solutionview, double-click form1.cs to open form1, select mainmenu in toolbox> win forms, and draw it in form1. In the word "typehere", we can enter a menu bar ,:
Double-click "About". The system will add the processing code for this menu bar. You can add the code to open the "about dialog box:
Protected void button#click (Object sender, system. eventargs E) { Aboutdlg DLG = new aboutdlg (); // assign an aboutdlg object
DLG. showdialog (); // display the dialog box
} |
Well, our program has been written. Let's press F5 to see the effect!
Note: The function of C # is far more than this. The purpose of this article is to get started with the development of Windows applications in C # using vc6 as soon as possible.