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:
Imports C1.WPF
•C#
using C1.WPF;
5. Add the following code to the event handlers added earlier:
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
•C#
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:
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
•C#
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.