We have a similar branding process here, and to go the resource assembly
route all you'd need to do is create your own ResourceManager subclass. Are
you using the Localizable property of the controls to put everything into a
resx file or are you doing it by hand? (the Localizable property forces all
values into the resx file, otherwise they just get persisted into the .cs
file).

Either way, it's relatively simple. Just create a subclass of
ResourceManager and override the GetString method (call the base, then do
your replaces, then return the result).

That said, if you're wanting to use the designer support and put <COMPANY>
into a label, have that value persisted into the resx file (again, requires
the Localizable property to be set to true) and be able to magically "hook"
into the resource manager, you have to do a little trickery in the designer
to basically overwrite the resource manager instance with your own.

In your InitializeComponent method when Localizable is set to true, you'll
notice something like so:
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(blah));

Then all of the properties of all of your controls are retrieved from the
resource manager instead of being retrieved directly from the code file. To
hook in here, here's what I did:

1) create a non-visual component (class that derives from IComponent) and
add it to every control/form
2) have that component provide a custom seralizer
3) have that serializer overwrite the resource manager reference

EXAMPLE CODE: note that we only use C# here so my CodeDom serialization just
writes out C# code instead
of using the appropriate CodeDom language-neutral structures

// component example
[DesignerSerializer(typeof(ResourceManagerComponentSerializer),
typeof(CodeDomSerializer))]
        public class ResourceManagerComponent :
System.ComponentModel.Component {
...

public ResourceManagerComponent(System.ComponentModel.IContainer container)
{
                        container.Add(this);
                        InitializeComponent();
                }

// serializer
public class ResourceManagerComponentSerializer : CodeDomSerializer {
                // just shell to the base deserializer
                public override object
Deserialize(IDesignerSerializationManager manager, object codeObject) {
                        CodeDomSerializer baseSerializer =
(CodeDomSerializer)

manager.GetSerializer(typeof(ResourceManagerComponent).BaseType,
typeof(CodeDomSerializer));

                        object retVal = baseSerializer.Deserialize(manager,
codeObject);
                        return retVal;
                }

                // simply insert a new expression (resources = new
XXXXXX(this.GetType());) at the top
                // of the serialization
                public override object
Serialize(IDesignerSerializationManager manager, object value) {
                        CodeDomSerializer baseSerializer =
(CodeDomSerializer)

manager.GetSerializer(typeof(ResourceManagerComponent).BaseType,
typeof(CodeDomSerializer));
                        ResourceManagerComponent component =
(ResourceManagerComponent) value;

                        object codeObject =
baseSerializer.Serialize(manager, value);
                        CodeStatementCollection statements = codeObject as
CodeStatementCollection;
                        if(statements != null) {
                                CodeAssignStatement resourcesStatement = new
CodeAssignStatement(
                                        new
CodeSnippetExpression("resources"),
                                        new CodeSnippetExpression("new
Globeranger.Core.UI.Forms.Resources.ResourceManager(this.GetType())") );
                                statements.Insert(0, resourcesStatement);
                        }
                        return codeObject;
                }

Adam..

> > -----Original Message-----
> > From: Unmoderated discussion of advanced .NET topics.
> > [mailto:[EMAIL PROTECTED] On Behalf Of
> Barnaby Gray
> > Sent: July 6, 2005 11:35 AM
> > To: [email protected]
> > Subject: [ADVANCED-DOTNET] Windows Form branding
> >
> >
> > I have a C# .NET application with lots of strings added through the
> > visual designer (thus stored in the form's .resx
> > file) specifying the application's company name and product name .
> >
> > What I want to do is change all of these instances to tags, for
> > example <COMPANY_NAME> or <PRODUCT_NAME> and then
> dynamically replace
> > these tags when the application runs with a company
> name/product name
> > etc of my choosing.
> >
> > I'm guessing this involves hooking into the process .NET uses to
> > extract the strings from the resx file and diplay them -
> does anybody
> > know how i might be able to go about this?

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to