Slide 9.2: Controlling program flow
Slide 9.4: An example of multiple forms (cont.)
Home

An Example of Multiple Forms


This example uses three forms:
  • The “Home” form on the right,
  • The “Happy” form showing a smiley face, and
  • The “Frown” form displaying a frown face.
and three methods: The following program implements the above form:
 using System;
 using System.Windows.Forms;

 namespace WindowsFormsApp4 {
   public partial class Home : Form {
     public Home( ) { InitializeComponent( ); }

     private void Button1_Click( object sender, EventArgs e ) {
       if ( radioButton1.Checked ) {
         Form f = new Happy( );
         f.Show( );
         this.Hide( );
       }
       else {
         Form f = new Frown( );
         f.Show( );
         this.Hide( );
       }
     }
     private void Button2_Click( object sender, EventArgs e ) {
       Application.Exit( );
     }
   }
 }