Click here to Skip to main content
13,294,840 members (70,666 online)
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 19 Apr 2008

Windows Mobile Globalization in Visual Studio

, 19 Apr 2008
Rate this:
Please Sign up or sign in to vote.
Simple technique to support multiple languages in Compact Framework WinForms.


The Compact Framework does not support changing Thread.CurrentUICulture to change a form's language on the fly.


This code defines a custom version of System.Globalization.ComponentResourceManager in the global namespace that inherits from the standard version and overrides ApplyResource() to use a custom culture. Code generated in InitializeComponent() will compile using this version, and the Forms Editor will not break because you do not change the generated code. Wrap the function in "pragma warning disable 436" to suppress the warning about using an ambiguous class reference.

Use the References node in the Properties sheet to change the alias for System from "global" to "global,ms".

extern alias ms;
using cm = ms::System.ComponentModel;
using System.Globalization;
using Wm2005Global;

namespace System.ComponentModel
    class ComponentResourceManager : cm.ComponentResourceManager
        public ComponentResourceManager(Type type) : base(type) { }
        public override void ApplyResources(object value, 
                        string objectName, CultureInfo culture)
            if (culture == null)
                culture = Program.Culture;
            base.ApplyResources(value, objectName, culture);

This shows how Visual Studio generates the normal code and uses the special version of ComponentResourceManager by default. The #pragma disables the warnings about using the ambiguous class:

#region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    #pragma warning disable 436
    private void InitializeComponent()
        System.ComponentModel.ComponentResourceManager resources = 
          new System.ComponentModel.ComponentResourceManager(typeof(Form1));
        this.mainMenu1 = new System.Windows.Forms.MainMenu();
        this.button1 = new System.Windows.Forms.Button();
        this.button2 = new System.Windows.Forms.Button();
        // button1
        resources.ApplyResources(this.button1, "button1");
        this.button1.Name = "button1";
        this.button1.Click += new System.EventHandler(this.button1_Click);
        // button2
        resources.ApplyResources(this.button2, "button2");
        this.button2.Name = "button2";
        this.button2.Click += new System.EventHandler(this.button2_Click);
        // Form1
        this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
        resources.ApplyResources(this, "$this");
        this.Menu = this.mainMenu1;
        this.Name = "Form1";
        this.Load += new System.EventHandler(this.Form1_Load);

#pragma warning restore 436

    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;

I think this is the cleanest possible solution to Globalization on Windows Mobile 2005. You do not have to change the default language for the entire device, and you can even change the language on a form from a menu item without closing it! This also demonstrates a technique for disposing all the controls on a form, calling InitializeComponent() and Form_Load() again, so it's like your form is recreated without closing it.


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionNeed common resource files instead of each form Pin
bagu4it14-Jun-13 2:38
memberbagu4it14-Jun-13 2:38 
QuestionHad somebody compiled those code passed? Pin
jeam25-Oct-11 4:33
memberjeam25-Oct-11 4:33 
GeneralBest Localization Plug-in for Visual Studio. Pin
Alexander Nesterenko17-Dec-08 22:44
memberAlexander Nesterenko17-Dec-08 22:44 
GeneralLook good Pin
Yves17-Nov-08 11:00
memberYves17-Nov-08 11:00 
GeneralAnother hack to get around CurrentUICulture Pin
FkYkko6-Nov-08 4:22
memberFkYkko6-Nov-08 4:22 
GeneralBrillant! [modified] Pin
Pablo Grisafi4-May-08 11:53
memberPablo Grisafi4-May-08 11:53 
GeneralMore explanation request Pin
Maruf Maniruzzaman19-Apr-08 17:22
memberMaruf Maniruzzaman19-Apr-08 17:22 
GeneralRe: More explanation request Pin
tbpub20-Apr-08 8:12
membertbpub20-Apr-08 8:12 
GeneralRe: More explanation request Pin
Anand.E2-Apr-14 6:28
memberAnand.E2-Apr-14 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 19 Apr 2008
Article Copyright 2008 by tbpub
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid