C # getting started and improving (III)

Source: Internet
Author: User
Chapter 2 use C # to develop the first Windows Application

Start preparation. Start vs7:

Then the following occurs:

Vs7 ide such:

1. Create a new 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!
Area A: it is our toolbox, including support for databases, components, form controls, etc. We can select and add it to form. If you cannot find toolbox, you can open toolbox by selecting toolbox in the menu view.
Area B: This 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: equivalent to the workspace in VC ++ 6: Solution Explorer can be regarded as the previous FileView. You must be familiar with resourceview and classview. Do you see form1.cs in Solution Explorer? This is the C # file corresponding to form1. Double-click it to design the form1 interface. Right-click form1.cs and select view code from the pop-up menu to view the corresponding code.
Area D: attribute window: similar to the attribute window in the resource editor in vc6/VB6, 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, select Local Project Items as the category, select Windows Form as the template, and enter the file Name AboutDlg. cs in Name to 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 the Toolbox, select the Label in Win Forms, and draw it in the form, and modify the Text in the attribute dialog box. We add a Button in Win Forms, its Text is set 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 about in 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 (); // create an aboutdlg object
DLG. showdialog (); // display dialog box
}

Well, our program has been written. Let's press F5 to see the effect!

Conclusion: This chapter describes how to write a Windows program. This is C #. Here I think you will feel a little bit about it, people who have studied VB/Delphi before may be surprised to say: how is this like VB/Delphi!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.