State Property [Visio 2003 SDK Documentation]
Determines a button's state, pressed or not pressed.
intRet = object**.State**
object**.State** = intExpression
intRet Integer. The state of the button.
object Required. An expression that returns a Menu, MenuItem, or ToolbarItem object.
intExpression Required Integer. The new state of the button.
Version added
2000
Remarks
The State property can be one of the following constants declared by the Visio type library in VisUIButtonState.
Constant | Value | Description |
---|---|---|
visButtonUp |
0 |
Button is not pressed |
visButtonDown |
-1 |
Button is pressed |
Example
This example shows how to use the State property to set the state of a toolbar button (make it appear pressed). The example adds a custom toolbar button to the Standard toolbar. Pressing the button saves the active document. This button appears in the Microsoft Office Visio user interface and is available while the document is active.
Before running this code, replace path\filename with the full path to and name of a valid icon (.ico) file on your computer.
To restore the built-in Visio toolbars after you run this macro, call the ThisDocument.ClearCustomToolbars method.
Sub State_Example()
Dim vsoUIObject As Visio.UIObject
Dim vsoToolbarSet As Visio.ToolbarSet
Dim vsoToolbarItems As Visio.ToolbarItems
Dim vsoToolbarItem As Visio.ToolbarItem
'Check whether there are document custom toolbars.
If ThisDocument.CustomToolbars Is Nothing Then
'If not, check whether there are application custom toolbars.
If Visio.Application.CustomToolbars Is Nothing Then
'If there are no custom toolbars, use the built-in toolbars.
Set vsoUIObject = Visio.Application.BuiltInToolbars(0)
Else
'If there are application custom toolbars, copy them.
Set vsoUIObject = Visio.Application.CustomToolbars.Clone
End If
Else
'If there already are document custom toolbars, use them.
Set vsoUIObject = ThisDocument.CustomToolbars
End If
'Get the Toolbars collection for the drawing window context.
Set vsoToolbarSet = vsoUIObject.ToolbarSets.ItemAtID(visUIObjSetDrawing)
'Get the set of toolbar items for the Standard toolbar.
Set vsoToolbarItems = vsoToolbarSet.Toolbars(0).ToolbarItems
'Add a new button in the first position.
Set vsoToolbarItem = vsoToolbarItems.AddAt(0)
'Set properties for the new toolbar button.
vsoToolbarItem.CntrlType = visCtrlTypeBUTTON
vsoToolbarItem.CmdNum = visCmdFileSave
vsoToolbarItem.Style = visButtonIconandCaption
vsoToolbarItem.State = visButtonDown
vsoToolbarItem.IconFileName "path\filename"
'Use the new UIObject object while this document is active.
ThisDocument.SetCustomToolbars vsoUIObject
End Sub
Applies to | Menu object | MenuItem object | ToolbarItem object