Microsoft 9GD00001 Computer Accessories User Manual


 
230 Microsoft Visual Studio 2010: A Beginner’s Guide
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ControlsCS
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
}
}
}
VB:
Class MainWindow
Private Sub Button1_Click(
ByVal sender As System.Object,
ByVal e As System.Windows.RoutedEventArgs)
Handles Button1.Click
End Sub
End Class
The Click event handler, just created, is the highlighted method, button1_Click
(Button1_Click in VB), that you see in Listing 8-1. We covered delegates and events in
Chapter 4, which you can review for a better understanding of how this method handles
the Click event. Notice how the VB code shows another way to handle events in VB, by
explicitly specifying Handles Button1.Click. Essentially, when a user clicks on the button
named button1, this handler will be called. This illustrates the concept of event-driven
programming, where you write handlers, such as button1_Click, that run code according