|
|||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionIn VS 2005 and earlier, resources were flagged as BackgroundI have been working on a large application organized into several projects. One of these is the "core" project, which holds various toolboxes, custom controls, etc. I wanted to put all of the app's icons and images here, too. We started out using VS 2005, which does not allow the resources of a project to be shared. The workaround turned out to be pretty simple: export the resources using a static class. After switching to VS 2008, my team decided to stick with using this export class. The structure allowed to pick which resources would be made public, to organize the resources into logical groupings, and to alias resources to show how they are to be used. The aliasing has proven especially useful, as it has allowed us to change an image in only two places -- the resource file and the exporting class -- and leave the rest of our code alone. The TheoryIn the accompanying solution, there is a code module named Public Class Images
Public Shared ReadOnly Property Leave() As Image
Get
Return My.Resources.Leave
End Get
End Property
Public Shared ReadOnly Property Page() As Image
Get
Return My.Resources.Page
End Get
End Property
Public Shared ReadOnly Property Report() As Image
Get
Return My.Resources.Page
End Get
End Property
Public Shared ReadOnly Property User() As Image
Get
Return My.Resources.User
End Get
End Property
End Class
In C#: using SharingResources_CS.Properties;
using System.Drawing;
public class Images
{
public static Image Leave
{
get { return Resources.Leave; }
}
public static Image Page
{
get { return Resources.Page; }
}
public static Image Report
{
get { return Resources.Page; }
}
public static Image User
{
get { return Resources.User; }
}
}
You can see that the resource We could have further broken this down in to additional classes, say, small images for use in menus and toolbars, and large images for panel backgrounds; the The Example SolutionsI have written two example solutions, one in VB and one in C#, using VS 2008. Each solution contains two projects. The first one implements the
|
||||||||||||||||||||||||||||||||