Skip to content

StateOptions Object

See Also

See Also

Description

The StateOptions object is used to store the CommandBar's save settings. The save settings are a set of options that will be used to change how and what will be saved and loaded when loading and saving XML files.

For a list of all members defined in this module, see StateOptions Members.

Remarks

The CreateStateOptions method is used to create a set of state options for the Command Bars.

The SaveStateToXMLString method uses the StateOptions object to determine how and what to save to the XML string. The LoadStateFromXMLString method uses the StateOptions object to determine how and what to load from a XML string.

When saving your XML string to a file, be sure to use the .XML file extension. If you open your .XML file in your favorite web browser, the XML string will automatically be formatted into the correct layout.

Example

Saving and Loading CommandBars Settings in XML Format

This sample illustrates how to use the StateOptions object to specify how and what of the CommandBars state, layout, options, etc., will be saved and loaded when the SaveStateToXMLString and LoadStateFromXMLString methods are called to save and load the CommandBars settings.

```vb '*********** ' Global Variables '*************

' Used to store XML string containing CommandBars settings Dim myXMLLayout As String

' Used to store the state options that specify how and what will be saved and loaded from the XML string. Dim myStateOptions As StateOptions

'*********** ' Form Load '*************

Private Sub MDIForm_Load() ' This will create a set of State options that will be used to change how and what will ' be saved and loaded when using the LoadStateFromXMLString and SaveStateFromXMLString methods Set myStateOptions = CommandBars.CreateStateOptions

' If True, no message boxes will be displayed when the CommandBar layout is loaded.
' i.e. The message box that asks for confirmation before the CommandBar layout is reset.
' The default is False
myStateOptions.LoadSilent = False

' If True, only CommandBars that have been customized will be saved.
' The default is True
myStateOptions.SaveOnlyCustomized = False

' If True, the original state of the CommandBars is saved along with the customized state
' For example, if a button on a toolbar is moved, then both the original and modified states will be saved.
' The Default is True
myStateOptions.SaveOriginalControls = True

' In the CommandBar Designer you can export a XCB file to a XML file and Load it using LoadFromXMLString.
' If SerializeDesignerControls is True, then the CommandBars.DesignerControls property will be filled with
' Control items from the CommandBar Designer's controls pane. This allows you to use LoadFromXMLString instead
' of the LoadDesignerBars method. NOTE: DesignerControls are the controls displayed in the customization dialog.
' The default is False
myStateOptions.SerializeDesignerControls = True

' If True, the controls in the CommandBars will be saved. If False, no controls will be saved,
' regardless of the other settings.
' The default is True
myStateOptions.SerializeControls = True

' If True, the images stored in the ImageManager will be saved.
' The default is False
myStateOptions.SerializeImages = True

' If True, the layout of the CommandBars will be saved. The Layout includes information such as
' bar position, location, and size.
' The Default is True
myStateOptions.SerializeLayout = True

' If True, the setting on the Keyboard and Options pages of the Customize dialog will
' be saved. This includes shortcut keys and CommandBar options like large icons and full menus.
' The default is False
myStateOptions.SerializeOptions = True

' Sets the commandBars theme to Office 2003
CommandBars.VisualTheme = xtpThemeOffice2003

' This subroutine is called to save a string in XML format that contains all of the CommandBars
' settings. The myStateOptions object specifies how and what will be saved to the XML string.
SaveXMLString

' Sets the new commandBars theme to Windows XP
CommandBars.VisualTheme = xtpThemeNativeWinXP

' This subroutine restores the CommandBars Settings with the settings saved when the SaveXMLString
' subroutine was called. In this sample, the theme would have been switched back to xtpThemeOffice2003.
LoadXMLString

End Sub

'*********** ' Subroutine used to create a string in XML format that contains all of the CommandBars settings and save ' this string to a XML file. '*************

Public Sub SaveXMLString() Dim FreeF As Integer, sFile As String, sLayout As String

On Error Resume Next:

' Creates a string containing the CommandBars layout, state, and settings. The state options stored in the myStateOptions
' object specifies which settings should be saved to the string. Since multiple strings can be saved
' to the same file, this string is given the profile name "CommandBarsMDISampleLayout"
myXMLLayout = CommandBars.SaveStateToXMLString("CommandBarsMDISampleLayout", myStateOptions)

' XML string will be saved to the file c:\Layout.xml. Note that the file extension is .XML. Opening a file
' of type XML in a web browser will correctly format the XML string.
sFile = "c:\Layout.xml"
FreeF = FreeFile
Kill sFile
Open sFile For Binary As #FreeF
Put #FreeF, , myXMLLayout
Close #FreeF

End Sub

'*********** ' Subroutine used to open a string in XML format from a XML file and restore the CommandBars ' settings with the settings stored in the XML string. The state options stored in the ' myStateOptions object will specify how the CommandBars settings will be restored. '*************

Public Sub LoadXMLString() Dim FreeF As Integer, sFile As String, sLayout As String

On Error Resume Next:

' XML string will be loaded from the file c:\Layout.xml.
sFile = "c:\Layout.xml"
FreeF = FreeFile
myXMLLayout = Space(FileLen(sFile))
Open sFile For Binary As #FreeF
Get #FreeF, , myXMLLayout
Close #FreeF
On Error Goto 0

' Load the "CommandBarsMDISampleLayout" profile from the myXMLLayout string. The state options stored in the
' myStateOptions object specify how to restore the Command Bars settings.
CommandBars.LoadStateFromXMLString "CommandBarsMDISampleLayout", myXMLLayout, myStateOptions

End Sub

See Also


Copyright (c) 1998-2024 Codejock Technologies. All rights reserved.