The following code demonstrates how to persist an existing NCommandBarsManager state:
C# |
Copy Code
|
---|---|
//create a command bars state object NCommandBarsState state = new NCommandBarsState(); //assign it a valid manager to work onto. state.Manager = this.nCommandBarsManager; //specify custom persistency flags - exclude image lists from serialization state.PersistencyFlags &= ~NCommandBarsState.Flags.ImageLists; //call the parameterless overload of the Save method //as it will automatically display a dialog box to choose file name state.Save(); |
Visual Basic |
Copy Code
|
---|---|
'create a command bars state object Dim state As NCommandBarsState = New NCommandBarsState() 'assign it a valid manager to work onto. state.Manager = Me.nCommandBarsManager 'specify custom persistency flags - exclude image lists from serialization state.PersistencyFlags ^= Not NCommandBarsState.Flags.ImageLists 'call the parameterless overload of the Save method 'as it will automatically display a dialog box to choose file name state.Save() |
The following code demonstrates how to load an existing command bars state:
C# |
Copy Code
|
---|---|
//create a NCommandBarsState object NCommandBarsState state = new NCommandBarsState(); state.Manager = this.nCommandBarsManager1; state.Load("c:\\myState.cbs"); |
Visual Basic |
Copy Code
|
---|---|
'create a NCommandBarsState object Dim state As NCommandBarsState = New NCommandBarsState() state.Manager = Me.nCommandBarsManager1 state.Load("c:\\myState.cbs") |
The NCommandBarsState object provides yet another useful feature - it supports direct read/write into a stream.
The following code demonstrates how to use read/write to stream methods:
C# |
Copy Code
|
---|---|
//create a NCommandBarsState object NCommandBarsState state = new NCommandBarsState(); state.Manager = this.nCommandBarsManager1; //create a memory stream object MemoryStream stream = new MemoryStream(); //save current state to the stream state.Write(stream); //you may load the same state to another manager state.Manager = this.nCommandBarsManager2; state.Read(stream); |