button click event of two buttons that use the same handler method. The sender parameter is cast as a Button type and interrogated to determine which button fired the event. private void Button_Click(object sender, RoutedEventArgs e) { Button btn = (Button)sender; if (btn.Name == "btnCancel") //Cancel code goes here else if (btn.Name == "btnSubmit") //Submit code goes here } } In the following activity, you will work with forms and controls to construct a simple memo viewer application that will allow users to load and view memo documents. ACTIVITY 11-1. WORKING WITH WINDOWS AND CONTROLS In this activity, you will become familiar with the following: • Creating a Windows Form-based GUI application. Working with Menu, StatusStrip, and Dialog controls. Working with Control events. Creating the Memo Viewer Interface To create the memo viewer interface, follow these steps: 1. Start Visual Studio. Select File > New > Project. Choose a WPF Application under the C# Projects folder. Rename the project to Act11_1 and click the OK button. The project contains a MainWindow.xaml file. This file is where you design the user interface. The project also contains a MainWindow.xaml.cs file. This is the codebehind file and it is where you will add the code to respond to the events. In the Window tag in the XAML Editor Window, add a Name attribute with a value of “MemoViewer”. Change the Title attribute to “Memo Viewer”. <Window x:Class="Act11_1.MainWindow" xmlns=" xmlns:x=" Name="MemoViewer" Title="Memo Viewer" Height="350" Width="525"> Add a DockPanel control in the Grid control. <Grid> <DockPanel LastChildFill="True"> </DockPanel> </Grid>
button click event of two buttons that use the same handler method. The sender parameter is cast as a Button type and interrogated to determine which button fired the event. private void Button_Click(object sender, RoutedEventArgs e) { Button btn = (Button)sender; if (btn.Name == "btnCancel") //Cancel code goes here else if (btn.Name == "btnSubmit") //Submit code goes here } } In the following activity, you will work with forms and controls to construct a simple memo viewer application that will allow users to load and view memo documents. ACTIVITY 11-1. WORKING WITH WINDOWS AND CONTROLS In this activity, you will become familiar with the following: • Creating a Windows Form-based GUI application. Working with Menu, StatusStrip, and Dialog controls. Working with Control events. Creating the Memo Viewer Interface To create the memo viewer interface, follow these steps: 1. Start Visual Studio. Select File > New > Project. Choose a WPF Application under the C# Projects folder. Rename the project to Act11_1 and click the OK button. The project contains a MainWindow.xaml file. This file is where you design the user interface. The project also contains a MainWindow.xaml.cs file. This is the codebehind file and it is where you will add the code to respond to the events. In the Window tag in the XAML Editor Window, add a Name attribute with a value of “MemoViewer”. Change the Title attribute to “Memo Viewer”. <Window x:Class="Act11_1.MainWindow" xmlns=" xmlns:x=" Name="MemoViewer" Title="Memo Viewer" Height="350" Width="525"> Add a DockPanel control in the Grid control. <Grid> <DockPanel LastChildFill="True"> </DockPanel> </Grid>