This sample illustrates how you can add a style gallery item to a style file. Here, a fill symbol is added to the current target style file. By default, this is the personal style file of the user, e.g. C:\WINNT\Profiles\user_name\Application Data\ESRI\ArcMap\user_name.style.
How to use
- Copy-paste the code from this sample into a module in the Visual Basic Editor.
- Run the procedure. It will add the fill symbol to the style gallery, and inform you of the file to which it added it.
- If you want to the symbol to be added to a particular style file, make it the target file using IStyleGalleryStorage::TargetFile before using IStyleGallery::AddItem.
Public Sub AddItemToStyleGallery()
Dim pMxDoc As IMxDocument
Dim pStyleGallery As IStyleGallery
Set pMxDoc = ThisDocument
Set pStyleGallery = pMxDoc.StyleGallery
'Create the new object
Dim pNewObject As IUnknown
Set pNewObject = New SimpleFillSymbol
'Assign properties specific to the style class
Dim pSimpleFillSymbol As ISimpleFillSymbol
Set pSimpleFillSymbol = pNewObject
Dim pRgbColor As IRgbColor
Set pRgbColor = New RgbColor
With pRgbColor
.Red = 55
.Green = 55
.Blue = 200
End With
pSimpleFillSymbol.Color = pRgbColor
'Create new style item using object
Dim pNewItem As IStyleGalleryItem
Set pNewItem = New StyleGalleryItem
pNewItem.Item = pNewObject
pNewItem.Name = "My True Blue"
pNewItem.Category = "My Fill Symbols"
'Add it to the current target style file
pStyleGallery.AddItem pNewItem
'Inform user where the symbol has been added
Dim pStyleStorage As IStyleGalleryStorage
Set pStyleStorage = pStyleGallery
MsgBox "Added a fill symbol to " & pStyleStorage.TargetFile
End Sub