Saving ToolbarControl items to a settings file
To save ToolbarControl items to a settings file, perform the following steps:
- Create a MemoryBlobStream and use the IToolbarControl.SaveItems method to save the items to that stream.
- Use the IBlobStream.SaveToFile method to save the stream to a settings file.
Loading ToolbarControl items from a settings file
To load ToolbarControl items from a settings file, perform the following steps:
- Create a MemoryBlobStream and load the file using the IBlobStream.LoadFromFile method.
- Use the IToolbarControl2.LoadItems method to load the stream into the ToolbarControl.
The IToolbarControl2.LoadItems method replaces the existing contents of the ToolbarControl.
The following code example shows both scenarios:
[C#]
private void SaveToolbarControl(string filePath)
{
//Create a MemoryBlobStream.
IBlobStream blobStream = new MemoryBlobStreamClass();
//Get the IStream interface.
IStream stream = (IStream)blobStream;
//Get the IToolbarControl2 interface.
IToolbarControl2 toolbarControl = (IToolbarControl2)axToolbarControl1.Object;
//Save the ToolbarControl into the stream.
toolbarControl.SaveItems(stream);
//Save the stream to a file.
blobStream.SaveToFile(filePath);
}
private void LoadToolbarControl(string filePath)
{
if (System.IO.File.Exists(filePath) == true)
{
//Create a MemoryBlobStream.
IBlobStream blobStream = new MemoryBlobStreamClass();
//Load the stream from the file.
blobStream.LoadFromFile(filePath);
//Get the IStream interface.
IStream stream = (IStream)blobStream;
//Get the IToolbarControl2 interface.
IToolbarControl2 toolbarControl = (IToolbarControl2)axToolbarControl1.Object;
//Load the stream into the ToolbarControl.
toolbarControl.LoadItems(stream);
}
}
[VB.NET]
Private Sub SaveToolbarControl()
'Create a MemoryBlobStream.
Dim blobStream As IBlobStream
blobStream = New MemoryBlobStreamClass
'Get the IStream interface.
Dim stream As IStream
stream = blobStream
'Get the IToolbarControl2 interface.
Dim toolbarControl As IToolbarControl2
toolbarControl = AxToolbarControl1.Object
'Save the ToolbarControl into the stream.
toolbarControl.SaveItems(stream)
'Save the stream to a file.
blobStream.SaveToFile(m_filePath)
End Sub
Private Sub LoadToolbarControl()
If System.IO.File.Exists(m_filePath) Then
'Create a MemoryBlobStream.
Dim blobStream As IBlobStream
blobStream = New MemoryBlobStreamClass
'Load the stream from the file.
blobStream.LoadFromFile(m_filePath)
'Get the IStream interface.
Dim stream As IStream
stream = blobStream
'Get the IToolbarControl2 interface.
Dim toolbarControl As IToolbarControl2
toolbarControl = AxToolbarControl1.Object
'Load the stream into the ToolbarControl.
toolbarControl.LoadItems(stream)
End If
End Sub
See Also:
ToolbarControl classIToolbarControl2 interface
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
ESRI.ArcGIS.Controls ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine |
ArcGIS for Desktop Basic | |
ArcGIS for Desktop Standard | |
ArcGIS for Desktop Advanced |