# Step 3 of 4: Adding Code

## Content

In the previous steps you set up the application's user interface and added controls to your application. In this step you'll add code to your application to finalize it.

Complete the following steps:

1. Return to the Design view of the form.
2. Select **Button1** on the form, navigate to the Properties window, click the lightning bolt **Events** icon to view events, and click the space next to the **Click** item to create a **Button1\_Click** event handler and switch to Code view.
3. Return to Design view and repeat the previous step with **Button2** to create the **Button2\_Click** event handler.
4. In Code view, add the following import statement to the top of the page:

 ```vbnet
 Imports C1.WPF
 OR
 Imports C1.Silverlight
 ```

 ```csharp
 using C1.WPF;
 OR
 using C1.Silverlight;
 ```

5. Add the following code to the event handlers added earlier:

 ```vbnet
 Private Sub Button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
     ShowWindow(False)
 End Sub
 Private Sub Button2_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
     ShowWindow(True)
 End Sub
 ```

 ```csharp
 void button1_Click(object sender, RoutedEventArgs e)
 {
   ShowWindow(false);
 }
 void button2_Click(object sender, RoutedEventArgs e)
 {
   ShowWindow(true);
 }
 ```

6. Add the following code below the Button\_Click event handlers:

 ```vbnet
 Private Sub ShowWindow(ByVal showModal As Boolean)
     Dim wnd As New C1Window()
     wnd.Header = "This is the header."
     wnd.Height = 120
     wnd.Width = 200
     wnd.Content = New MyWindow()
     wnd.CenterOnScreen()
     If showModal Then
         wnd.ShowModal()
     Else
         wnd.Show()
     End If
 End Sub
 ```

 ```csharp
 private void ShowWindow(bool showModal)
 {
     C1Window wnd = new C1Window();
     wnd.Header = "This is the header.";
     wnd.Height = 120;
     wnd.Width = 200;
     wnd.Content = new MyWindow();
     wnd.CenterOnScreen();
     if (showModal)
       wnd.ShowModal();
     else
       wnd.Show();
 }
 ```

This code specifies the size of the window and opens a new window.

In this step you completed adding code to your application. In the next step you'll run the application and observe run-time interactions.