(original) C # learning Note 02--Writing C # program 03--windows Forms application

Source: Internet
Author: User

2.3 Windows Forms applications

This explanation explains how to create a Windows Forms application, reference: (original) C # learning Note 02--Writing C # program 01--development environment, modify to select: Windows forms Application. Such as:

After you create the project, you should see a blank Windows Form after you click the OK button. Move the mouse pointer over the toolbox bar on the left side of the screen, and then move to the button option on the All Windows Forms tab, and double-click on the option to add a button to the application's main form (FORM1).

Double-click the button you just added to the form.

The C # code in Form1.cs should now be displayed. Make the following changes:

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacewindowsformsapplication1{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Private voidButton1_Click (Objectsender, EventArgs e) { MessageBox.Show (  "ThefirstWindows app in the book! " ); }    }}

Run the application. Stand-alone Display button, open a message dialog box, the result is as follows:

Click OK. Like every standard Windows application, click the X icon in the upper-right corner to exit the application.

(Again, you can use other UI artifacts in the Windows Forms section of the Toolbox.) )

Use the tabs in the main window to switch back to the Design view of the form. Click the button and select it. The Properties window at the bottom right of the screen displays the properties of the button control (the properties of the control are very similar to the properties of the file in the previous example). Make sure the application is not currently running, scroll down to the Text property, it is currently set to Button1, and change its value to click Me. such as the Red circle part:

This button has many properties, from the simple format of the button color and size, to some fuzzy settings (such as data binding settings, it can establish a connection with the database), everything.

Let's look at the Code Changes section, first open the Form1.Designer.cs file, the code is as follows:

  

See the Red Circle section, click the plus sign to expand, somewhere you can see the following code:

 This " Click Me ";

Instead of thinking too much about the syntax used here, we can see that the text you type in the Properties window appears directly in the code. Ha ha!!

(original) C # learning Note 02--Writing C # program 03--windows Forms application

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.