CHAPTER 19 BUILDING A BETTER WINDOW WITH (Web design conference)

CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.624 STEM.WINDOWS.FORMS Right-click the Form1.cs icon and select View Code. Here you will see a partial class that contains all of the Form s event handlers, constructors, overrides, and any member you author yourself (note that I renamed this initial class from Form1 to MainWindow using the Rename refactoring): namespace MyVisualStudioWinApp { public partial class MainWindow : Form { public MainWindow() { InitializeComponent(); } } } The default constructor of your Form makes a call to a method named InitializeComponent(), which is defined within the related *.Designer.cs file. This method is maintained on your behalf by Visual Studio 2005, and it contains all of the code representing your design-time modifications. To illustrate, switch back to the Forms designer and locate the Text property in the Properties window. Change this value to something like My Test Window. Now open your Form1.Designer.cs file and notice that InitializeComponent() has been updated accordingly: private void InitializeComponent() { … this.Text = “My Test Window”; } In addition to maintaining InitializeComponent(), the *.Designer.cs file will define the member variables that represent each control placed on the designer. Again, to illustrate, drag a Button control onto the Forms designer. Now, using the Properties window, rename your member variable from button1 to btnTestButton via the Name property. Note It is always a good idea to rename the controls you place on the designer before handling events. If you fail to do so, you will most likely end up with a number of nondescript event handlers, such as button27_Click, given that the default names simply suffix a numerical value to the variable name. Figure 19-10. Each Form is composed of two *.cs files.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Leave a Reply