NewLabel

Description

Adds a label control to a form

Syntax

[Set oCtl =] oFrm.NewLabel

( Name, Left, Top, Width, Height, Caption, [Container] )

Parameters

Part

Description

Set oCtl =

(optional) Store a reference to the new control in the variable oCtl. This variable can be used to access the control's properties and methods.

oFrm

A reference to a form object (see the NewForm method)

Name

The name of the control. It must be unique within the form and may not be empty or start with an asterisk (*)

Left

See the list of properties below

Top

See the list of properties below

Width

See the list of properties below

Height

See the list of properties below

Caption

See the list of properties below

Container

(optional) The name of an existing frame control that will act as container for the label. If unspecified or an empty string, the Form itself will be the container. Please note that the Left and Top properties are relative to the container's left and top edges

Properties and Methods

Property

Description

Alignment

0

Text is left-aligned (default)

1

Text is right-aligned

2

Text is centered

Autosize

(boolean) Automatically resize the control to display it's entire contents

BackColor

Background color (use the RGB function to assign a color value)

BackStyle

0

Transparent - background color and any graphics are visible behind the control

1

Opaque — the control's BackColor property setting fills the control and obscures any color or graphics behind it (default)

BorderStyle

0

None (default)

1

Fixed single

Caption

The text to be displayed (unlimited size). If you specify an access key for the control by including an ampersand sign (&), the focus will move to the next control in the taborder when the user presses Alt+access key

Enabled

(boolean) Determines if the control can respond to user-generated events

Fontname

The font used to display text. The default is determined by the system. Check the glossary for an explanation about setting font properties.

Fontsize

The size of the font in points. The maximum is 2160 points.

Fontbold

(boolean) Enable or disable the bold style of a font

Fontitalic

(boolean) Enable or disable the italic style of a font

Fontstrikethru

(boolean) Enable or disable the strikethru style of a font

Fontunderline

(boolean) Enable or disable the underline style of a font

ForeColor

Foreground color (use the RGB function to assign a color value)

Height

The height of the control in twips

Left

The distance from the left edge of the specified container in twips

Parent

(read-only) Returns the parent form, object or collection. You can use the parent property to access the properties and methods of an object's parent

TabStop

(boolean) Determines whether the TAB key can be used to move the focus

Tag

(reserved) Used internally to store the user-defined controlname

ToolTipText

Explanatory text that appears in a small rectangle below the object when you pause the mouse pointer (hover) over it for about one second

Top

The distance from the top edge of the specified container in twips

UseMnemonic

(boolean) Determines whether ampersand characters (&) in the caption cause the character following it to become an access key (default) or not.

Visible

(boolean) Determines whether the control is visible or hidden

Width

The width of the control in twips

WordWrap

Determines whether the control expands vertically or horizontally to fit the text when the Autosize property set to True

True

The text wraps; the control expands or contracts vertically to fit the text and the size of the font. The horizontal size doesn't change.

False

(default) The text doesn't wrap; the control expands or contracts horizontally to fit the length of the text and vertically to fit the size of the font and the number of lines.

Method

Description

Move

Parameters: left [, top [, width [, height ]]]

Only the left argument is required. However, to specify any other arguments, you must specify all arguments that appear in the syntax before the argument you want to specify. For example, you can't specify width without specifying left and top. Any trailing arguments that are unspecified remain unchanged

Refresh

Forces a complete repaint of a control

Example

Option Explicit

Const vbModal = 1

Dim oDlg, oFrm, oCtl

'Create the WshDialog.Kit object and store a reference in oDlg
Set oDlg = Wscript.CreateObject("WshDialog.Kit", "oDlg_")

'Add a new form and store a reference to it in the variable oFrm
Set oFrm = oDlg.NewForm("Sample")

'Add an icon
oFrm.NewImage "ICON", 200, 100, 0, 0, "IconInformation"

'Add a label LBL1 to the form and store a reference in the variable oCtl
Set oCtl = oFrm.NewLabel("LBL1", 1000, 200, 2000, 300, "Label Caption")

'Use the reference variable to modify the borderstyle property
oCtl.BorderStyle = 1

'This does the same but uses oFrm.Ctl(<controlname>) to get a reference
oFrm.Ctl("LBL1").BorderStyle = 1

'Add an OK button and set it's Default property
Set oCtl = oFrm.NewButton("OK", 3500, 200, 1000, 375, "&OK")
oCtl.Default = True

'Automatically size the form and show it (modally)
oFrm.Autosize
oFrm.Show vbModal