Example introduction of C # GUI development

Source: Internet
Author: User
Tags class definition

In this article, we will experience the C # GUI development process by editing a small program that converts temperature from Celsius to Fahrenheit. The basic requirement for reading this article is that you have basic knowledge of C # and object-oriented programming. The purpose of this article is to introduce C #, and if you want to compile or run the programs listed in this article, you need support for the. NET Framework SDK.

Creating a Windows application consists primarily of the following basic steps: Creating the appropriate form, adding control to the form, and finally adding code. The C # and. NET framework needed to complete the above process can be found in System.WinForms namespace.

The first step is to create the form.

We use Class System.WinForms as the origin, create a class, and then initialize the attribute. For example, the definition of class begins as follows

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

Here are the main window styles we want

Size is 180*90 pixel

You cannot modify the window size arbitrarily.

Title shown as °c->°f/°f->°c

The form appears in the center of the screen

We don't need the Help button (our application is so simple that we don't need this kind of help)

We do not need to give users permission to enlarge the scope of the program's Windows (because everything is clearly visible in a given size).

Initializes the form by setting the property value of the Tempconverter object. There are two ways to set a property value:

First, use the method to set the property value

Second, through the attribute variable directly set.

The following code. If you want to know more about the properties and methods of the WinForms class, you can refer to the random files of the. NET Framework SDK.

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

With the above steps, we can connect all the code together, so that we can easily edit, run the program to watch the appearance of the form. To do this, we use the class definition to create a constructor that contains the code mentioned above and initializes the main window's appearance, and then you need to create a main method. The following steps are established:

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() );
}
}

A new statement appears in Main ():

Application.Run (New Tempconverter ());

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.