Chapter 4 Control Structures: Part 1 129 Text (Starting a web site)
Chapter 4 Control Structures: Part 1 129 Text property value Fig. 4.22 New Text property value reflected in design mode. 4. Change the label s Text property at runtime. In the previous steps, we set properties at design time. Often, however, it is necessary to modify a property while a program is running. For example, to display the result of a calculation, a label s text can be assigned a string containing the result. In console applications, such code is located in Main. In Windows applications, we must create a method that executes when the form is loaded into memory during program execution. Like Main, this method is invoked when the program is run. Double-clicking the form in design view adds a method named ASimpleProgram_Load to the class (Fig. 4.23). The cursor is placed in the body of the ASimpleProgram_Load method definition. Notice that ASimpleProgram_Load is not part of the Windows Form Designer generated code. Add the statement welcomeLabel.Text=”C#”; in the body of the method definition (Fig. 4.23). In C#, properties are accessed by placing the property name (i.e., Text) after the object name (i.e., welcomeLabel), separated by the dot operator. This syntax is similar to that used when accessing object methods. Notice that the IntelliSense feature displays the Text property in the member list after the class name and dot operator have been typed (Fig. 4.29). In Chapter 8, Object-Based Programming, we discuss how programmers can create their own properties. ASimpleProgram_Load method Fig. 4.23 Method FrmASimpleProgram_Load.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web design programs services