NewButton |
Description
Adds a commandbutton control to a form |
Syntax
[Set oCtl =] oFrm. NewButton |
( 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 button. 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, Methods and Events
Property |
Description |
|
Cancel |
(boolean) Indicates whether a commandbutton acts as Cancel button.The difference with other buttons is that users can select a Cancel button by pressing the Esc key. Only one button on a form can be the Cancel button. When you enable the Cancel property for one button, it is automatically disabled for all other buttons on the form |
|
Caption |
The text displayed in the control (maximum 255 character). You can specify an access key for the control by including an ampersand sign (&) |
|
Default |
(boolean) Indicates whether a commandbutton is the Default button.The default button can be chosen by pressing the ENTER key (unless the user has moved the focus to another commandbutton on the same form). Only one button on a form can be the Default button. When you enable the Default property for one button, it is automatically disabled for all other buttons on the form. Setting this property from code has no effect, the first commandbutton you add will automatically become the Default button. |
|
DisabledPicture |
Returns or sets a graphic to be displayed when the button is disabled. |
|
DownPicture |
Returns or sets a graphic to be displayed when the button is in the down position. See the Picture property below for additional information |
|
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 |
|
Fontunderline |
(boolean) Enable or disable the underline style of a font |
|
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 |
|
Picture |
Returns or sets a graphic to be displayed in the control. This property can be set to any other object's DragIcon, Icon, Image, or Picture property, or you can assign it a graphic returned by the LoadPic function |
|
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 |
|
Value |
(boolean) Returns or sets a value indicating whether the button is chosen. |
|
Visible |
(boolean) Determines whether the control is visible or hidden |
|
Width |
The width of the control in twips |
|
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 |
|
SetFocus |
Moves the focus to the specified control |
|
Event |
Description |
Event raised |
Click |
Occurs when clicking the control with the left mouse button, by pressing an ACCESS KEY for the control, pressing the SPACEBAR or ENTER when the control has the focus, pressing ESC for a control with its Cancel property set to True or setting the Value property to True from code |
Controlname |
To be able to handle events you need to operate a form in callback mode. |
Example
Option Explicit 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 OK button and store a reference in the variable oCtl Set oCtl = oFrm.NewButton("OK", 150, 150, 1000, 375, "&OK") 'Enable the Default property (the button can be selected by pressing ENTER) oCtl.Default = True 'Add a Cancel button and store a reference in the variable oCtl Set oCtl = oFrm.NewButton("CANCEL", 1500, 150, 1000, 375, "&Cancel") 'Enable the Cancel property (the button can be selected by pressing ESC) oCtl.Cancel = True 'Automatically size the form and show it (modally) oFrm.Autosize oFrm.Show vbModal 'Show which button was selected to dismiss the form MsgBox "The " & oDlg.Clicked & " button was selected" |