JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Setting a Control's Style

One important method you can use for customizing your applications is changing the style of a Web form or the controls it contains. This demands knowledge of cascading style sheets, CSS, which you can pick up in a book such as the HTML Black Book (Coriolis Group, 2000). To handle styles, you can use the Style property of Web forms and Web server controls.

For example, in the Controls example on the CD-ROM, I change the background color of the displayed text box by accessing the background color part of its style as TextBox1.Style("BACKGROUND-COLOR"). In the Controls example, I set the text box's background color to aqua this way (this works because "aqua" is a predefined color in the Internet Explorer):

    Private Sub Button3_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Style("BACKGROUND-COLOR") = "aqua"
    End Sub

You can see the result in Figure 15.4 (although the aqua background isn't very evident in the black-and-white figure).

Click To expand
Figure 15.4: Changing a text box's style

In this way, you can change all style attributes of controls. (For an example, refer to the topic "Moving Controls" in this chapter to see how to set the position of controls using styles.)

Tip 

You can set the CssClass property of a control to a CSS style class defined in the Styles.css file that is a part of Web applications.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor