Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

C# Windows Forms



Windows Forms

C# programmers have made extensive use of forms to build user interfaces. Each time you create a Windows application, Visual Studio will display a default blank form, onto which you can drag the controls onto your applications main Form and adjust their size and position.

The first step is to start a new project and build a form. Open your Visual Studio and select File->New Project and from the new project dialogue box select Other Languages->Visual C# and select Windows Forms Application. Enter a project name at the bottom of the dialogue box and click OK button. The following picture shows how to create a new form in Visual Studio.

Select Windows Forms Application from the New Project dialogue box.

After selecting Windows Forms Application, you can see a default form (Form1) in your new C# project. The Windows Form you see in Designer view is a visual representation of the window that will open when your application is opened. You can switch between this view and Code view at any time by right-clicking the design surface or code window and then clicking View Code or View Designer. The following picture shows how is the default Form (Form1) looks like.

At the top of the Form, there is a title bar which displays the title of the Form. Form1 is the default name, and you can change the name to your convenience. The title bar also includes the control box, which holds the minimize, maximize, and close buttons.

If you want to set any properties of the Form, you can use the Visual Studio Property window to change it. If you do not see the Properties window, on the View menu, click Properties window. This window lists the properties of the currently selected Windows Form or control, and it’s here that you can change the existing values.

For example, to change the title of the Form from Form1 to MyForm, click on Form1 and move to the right side down Properties window, set Text property to MyForm. Then you can see the Title of the Form is changed. Likewise, you can set any properties of Form through the Properties window.

You can also set the properties of the Form1 through coding. For coding, you should right-click the design surface or code window and then click View Code.

When you right-click on Form then you will get code-behind window, there you can write your code

For example, if you want to change the back colour of the Form to Brown, you can code in the Form1_Load event like the following.

Likewise, you can change other properties of Form1 through coding.

private void Form1_Load(object sender, EventArgs e)
{
    this.BackColor = Color.Brown;
}

Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More