Slide 8.3: A simple C# application
Slide 8.5: Keywords
Home

A Simple C# Application (Cont.)

  1. Double click on Form1, the Code Editor for Form1 as shown below will appear. The top of the Code Editor consists of a list of objects such as Form and their associated events or procedures such as Load.



  2. Enter the following two commands in the method Form1_Load:

    • In order to display the output of the program, you have to add the this.show( ) statement.

    • The command label1.Text displays the output on the label.

    After building the project, click on the Debug menu to run the program and you will get the output as shown in the previous slide.

     using System;
     using System.Windows.Forms;
    
     namespace WindowsFormsApp2 {
       public partial class Form1 : Form {
         public Form1( ) { InitializeComponent( ); }
    
         private void Form1_Load( object sender, EventArgs e ) {
           this.Show( );
           label1.Text = "Welcome to C#!";
         }
       }
     }

    where the method InitializeComponent loads the compiled page of a component. Just leave it there.