C # Introduction to programming trilogy: Step 1: create a form

Source: Internet
Author: User

# Is the main development language of Microsoft. NET architecture. It is widely used and powerful, and Web developers should not hesitate to embrace it. This article describes how to convert the temperature of C #

GUI programming is introduced to guide you into the powerful and magical programming world of C.

Prerequisites

To understand the routines mentioned in this article, we must first have a basic understanding of C # and object-oriented programming. For more information about C #, see C #

As a program developer, we all know that creating a typical windows-based application should include the following basic steps: creating an appropriate form and adding controls to the form; finally, code is added to respond to user events.

After the C # And. NET frameworks appear, all the tools required to complete these steps can be found in the System. WinForms namespace.

Step 1 create a form

This is very simple. You only need to create a class derived from the System. WinForms. Form class and initialize the appropriate attributes. In our example, the class definition starts like this:

Public class TempConverter: System. WinForms. Form {
.
.
.
}

The following is the expected main window (form) View:

We want the form to have the following features:

-The window size is 180x90 pixels.

-The window size cannot be changed.

-The title displayed in the title bar is + C-> + F/+ F-> + C

-In the initial status, the form is displayed in the center of the screen.

-Do not want a Help button (the application is too simple and does not need a Help button)

-Do not provide users with the ability to maximize applications

(Because everything is visible within the given window size, you do not need to maximize it)

Initializing a form to a given specification involves setting certain properties of the TempConverter object. Some attributes have methods to change values, while other attributes must be directly modified by updating appropriate instance variables. The following is the code. For more information about WinForms

For more information about class attributes and methods, the documentation provided by the. NET Framework SDK can be a good reference.

This. SetSize (180,90 );
This. BorderStyle = FormBorderStyle. FixedDialog;
This. Text = "+ C-> + F/+ F-> + C ";
This. StartPosition = FormStartPosition. CenterScreen;
This. HelpButton = false;
This. MaximizeBox = false;

Now we can compile and run the Code together to see what the form looks like after it is run. Here you need to use the class definition to create a constructor (including the above Code to initialize the appearance of the Main Window), and create a main method to create an example of the class. The following code completes this task:

Public class TempConverter: System. WinForms. Form {

Public TempConverter (){
This. SetSize (180,90 );
This. BorderStyle = FormBorderStyle. FixedDialog;
This. Text = "+ C-> + F/+ F-> + C ";
This. StartPosition = FormStartPosition. CenterScreen;
This. HelpButton = false;
This. MaximizeBox = false;
}

Public static void Main (){
Application. Run (new TempConverter ());
}
}

The above only shows the new code in the row where the Main () method is located.

Application. Run (new TempConverter ());

The above line means starting the application with a new form.

If the source file is called TempConverter. cs, run the following command to compile the Code:

Csc/r: System. dll/r: Microsoft. Win32.Interop. dll/r: System. WinForms. dll TempConverter. cs

Compilation commands are not described in detail here, because when Visual Studio. NET is available, you do not need to issue command line compilation commands.

Related Article

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.