Using Visual Basic and Dynamic HTML, you can easily change the styles of elements on the pages that make up your application's user interface. You do by manipulating the properties of page elements.
Setting and retrieving properties for elements on an HTML page works differently than it does for controls on a form. In a form, you access the properties of a control directly by referencing the name of the control and the name of the property you want. For most elements in a Web page, you must use a secondary object known as the Style object to access properties for an element.
When you want to set a physical property such as background color, you use a collection called Style to access the appropriate property. The following table shows how you set and retrieve properties in standard Visual Basic applications and in DHTML applications. In this example, properties are being set and retrieved for a command button with the ID "Button1."
Setting and Retrieving Property Values
Setting a Property | Retrieving a Property Value | |
In Visual Basic |
|
|
In Dynamic HTML |
|
|
Note Color names in DHTML applications are different from the color names you use in forms-based Visual Basic applications. When you specify a color for a page element, you must either specify an RGB value (such as #5F9EA0) or a color label as specified by Internet Explorer 4 (such as "cadetblue"). A full list of the color names supported by Internet Explorer 4 can be found in the Color Table topic in the Dynamic HTML section of the Internet Client SDK.
The only element within an HTML page to which the Style object syntax does not apply is the document itself. You do not use the style property to set the background color or other physical properties for the document. Instead, you access those properties directly as shown in the following code:
Document.bgcolor = "lightyellow"
Document.fgcolor = "slateblue"
The following code shows how you retrieve the RGB value for the background color for the Document object:
Dim Color as string
Color = Document.bgcolor
Note The fgcolor property sets the color for the page's text elements only.
The style properties you use to set the physical appearance of an HTML element are named differently than their corresponding properties in Visual Basic. The following table lists a few of the more frequently used styles and explains their use.
DHTML Style | Purpose |
backgroundcolor | Setting the background color of all elements except the Document object, which represents the body of the page. For the page itself, the property is called bgcolor. |
border | Setting a border around any element. All elements on an HTML page can have a border, including paragraphs of text. |
color | Setting the foreground color for all elements except the Document object, which represents the body of the page. For the page itself, the property is called fgcolor. |
font | Setting the font for the element. A series of related properties (fontfamily, fontsize, fontstyle, etc.) are used to fine-tune the appearance of the font. |
margin | Controlling the distance between the border of the element and the edge of the page. This property can be set to control all of the element's margins, or you can set the top, bottom, left, and right margins independently through a series of related properties. |
padding | Controlling the distance between the inner text of the element and its border. This property can be set to control the padding space on all sides of the elements, or you can set the padding of the top, bottom, left, and right sides independently through a series of related properties. |
textdecoration | Formatting text within an element. You use this property to make the text blink, or to display it with a strikethrough, underline, or overline. |
For More Information For more information on the Style collection, any of the properties listed above, or other style-related properties in Dynamic HTML, see "Dynamic HTML" in the Internet Client SDK, available on your MSDN CD.