CHAPTER 19 BUILDING A BETTER WINDOW WITH (My space web page)

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS 625 Handling Events at Design Time Notice that the Properties window has a button depicting a lightning bolt. Although you are always free to handle Form-level events by authoring the necessary logic by hand (as done in the previous examples), this event button allows you to visually handle an event for a given control. Simply select the control you wish to interact with from the drop-down list box (mounted at the top of the Properties window), locate the event you are interested in handling, and type in the name to be used as an event handler (or simply double-click the event to generate a default name of the form ControlName_ EventName). Assuming you have handled the Click event for the Button control, you will find that the Form1.cs file contains the following event handler: public partial class MainWindow : Form { public MainWindow() { InitializeComponent(); } private void btnButtonTest_Click(object sender, EventArgs e) { } } As well, the Form1.Designer.cs file contains the necessary infrastructure and member variable declaration: partial class MainWindow { … private void InitializeComponent() { … this.btnButtonTest.Click += new System.EventHandler(this.btnButtonTest_Click); } private System.Windows.Forms.Button btnButtonTest; } Note Every control has a default event, which refers to the event that will be handled if you double-click the item on the control using the Forms designer. For example, a Form s default event is Load, and if you double-click anywhere on a Form type, the IDE will automatically write code to handle this event. The Program Class Beyond the Form-centric files, a Visual Studio 2005 Windows application defines a second class that represents the application object (e.g., the type defining the Main() method). Notice that the Main() method has been configured to call Application.EnableVisualStyles() as well as Application.Run(): static class Program { [STAThread] static void Main() { Application.EnableVisualStyles();
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Leave a Reply