Something I wanted to streamline for my development team was icon and bitmap management; or rather taking as much of the decision making process out of the equation. The strategies I have taken have the following benefits.
Time / Efficiency
- I don’t want developers spending any time digging around for or capturing an icon/bitmap. Period.
- I don’t want 10 different methods written to assign an image to a control; which would require a minimum of 10 unit tests be written, and so on.
- I do want to be able to change an icon or bitmap in one place and have that automatically update all projects. Really, how many copies of the folder browser image do you need across projects?
- I want a single location where our custom ArcGIS command icons are stored.
Consistent Presentation Layer
- Icons and bitmaps should be consistent across the presentation layers. I prefer to use Windows icons to ensure user recognition of functionality and purpose. I don’t want icons from different Windows OS mixed either. Office XP icons look dated on Vista… And Office 2000 icons look like ass on XP and Vista. By the same token, if your company has spent the money and bought an icon library then you want only images from that library used in your software. The one acception to this rule is the outdated ArcGIS icon library. I will mix these into my UI for example when a button’s functionality is to select features.
What follows is a brief primer on how to get started building an icon and bitmap library, and a utility class with methods for retrieving those images.
The Utilities Assembly
I have created a sample Utilities library to be referenced by any project requiring icons or bitmaps. This includes custom Windows Forms, ArcGIS ICommand classes, custom property pages, etc. This project contains a “Resources” folder that holds the icons and bitmaps, has entries in the Resources.resx file, and an IconHelper class.
Adding Icons and Bitmaps
I started by first creating a “Resources” folder within the project. Next, I built my icon and bitmap library by adding the desired icons and bitmaps to that folder. I rename these files appending “Icon” or “Bitmap” (Example: Save.ico to SaveIcon.ico). This makes it easier to identify the image type when using the My feature in VB.NET (Example: My.Resources.SaveIcon).
The IconHelper Class
I created enums for both icons and bitmaps providing intuitive names… the actual file name minus the “Icon” or “Bitmap” you may have appended to it. Here you could do some logical groupings if you wanted for such things as EnumTextEditorIcons and such.
This is just one example that is included in the sample.
The enum:
”’ <summary>
”’ Enum for common Icons.
”’ </summary>
Public Enum EnumIcon
AddNew
Copy
Delete
ErrorProvider
Folder
Help
etc…
End Enum
The method to retrieve the icon using the enum:
”’ <summary>
”’ Gets an icon from the embedded resources.
”’ </summary>
”’ <param name=”iconImage”>The icon image.</param>
Shared Function GetIcon(ByVal iconImage As EnumIcon) As Icon
Select Case iconImage
Case EnumIcon.AddNew
Return My.Resources.AddNewIcon
Case EnumIcon.Copy
Return My.Resources.CopyIcon
Case EnumIcon.Delete
Return My.Resources.DeleteIcon
Case EnumIcon.Folder
Return My.Resources.FolderIcon
Case EnumIcon.Help
Return My.Resources.HelpIcon
etc…
Case Else
Return Nothing
End Select
End Function
Putting it all together in the UI:
‘ Assign an image to a Button control
Me.FolderBrowserButton.Image = _
IconHelper.GetIcon(EnumIcon.Folder).ToBitmap()
‘Add bitmap MxCommand
MyBase.m_bitmap = _
IconHelper.GetIcon(EnumCustomArcGisCommands.ReportsGenerator).ToBitmap()
The Sample
The sample illustrates how to use the utility class in a Windows Form and shows other ways to expand this idea.
Download VB.NET sample or C# sample.

