0

I'm working on one application to which i would like to support localization. i have implemented the Satellite assembly concept to implement the Localization but the problem is it will load/render the text of all controls at runtime based on the chosen language which makes my application loading very slow.

now my question is : is there any better approach through which i can update all of my Main Form controls without delay/flickering while loading time.

I'm developing the application using c#.net Winforms.

My Project structure:

enter image description here

here is what i have tried [sample code]:

Note : this works fine because this sample application only contains the very few controls but my actual application contains too many controls which definatly will delay/flicker while loading.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Resources;
using System.Reflection;
using System.Globalization;
using System.Threading;

namespace Localization
{
    public partial class Form1 : Form
    {
        #region constants

        const String DEFAULT_CULTURE = "en-US";

        #endregion

        ResourceManager resourceManager = null;
        public Form1()
        {
            InitializeComponent();
            resourceManager = new ResourceManager("Localization.Resources", Assembly.GetExecutingAssembly());
        }

        private void cmbSelectLanguages_SelectedIndexChanged(object sender, EventArgs e)
        {
            String languageCode = "";
            switch (cmbSelectLanguages.SelectedItem.ToString())
            {
                case "German": languageCode = "de-DE";
                    break;
                case "French": languageCode = "fr-FR";
                    break;

                case "English": languageCode = DEFAULT_CULTURE;
                    break;

                default: languageCode = DEFAULT_CULTURE;
                    break;
            }
            SetCulture(languageCode);
            SetControlsText();
        }
        private void SetCulture(String languageCode)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(languageCode);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //set the default languge to US-English while loading the form
            SetCulture(DEFAULT_CULTURE);
            SetControlsText();
        }
        private void SetControlsText()
        {
            lblCulture.Text = " " + System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
            lblUserName.Text = resourceManager.GetString("lblUsername");
            lblPassword.Text = resourceManager.GetString("lblPassword");
            btnLogin.Text = resourceManager.GetString("lblLogin");
            btnCancel.Text = resourceManager.GetString("lblCancel");
            lblChooseLanguage.Text = resourceManager.GetString("lblChooseLanguage");
            lblLoginTitle.Text = resourceManager.GetString("lblUserLogin");
            pic.Image = (Image)resourceManager.GetObject("Login");
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {

        }

        private void btnLogin_Click(object sender, EventArgs e)
        {

        }
    }
}

enter image description here

enter image description here

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67

1 Answers1

0

Not sure why you're having performance issues but try downloading the developer's version of my application at http://www.hexadigm.com/freedownloads.aspx. Load the "Sample Solution" which you can find under "Hexadigm Systems" in the Windows Start menu and take a look at the code (it's not long). It does what you're attempting to do and there's no flicker. Your own technique could be responsible for that flicker or perhaps your environment (particular controls, etc.), but I'd have to investigate further (for instance, see the calls to "SuspendAllLayout()" and "ResumeAllLayout()" in my code, which might impact performance for some forms if not implemented). Note that my code shouldn't be considered a model for how to do it however. It was quickly written as I was only experimenting at the time (years ago), but it's likely close to the "official" way you should do it. In fact, it was intended to be the basis of a generic "RefreshLanguage()" (extension) method of some kind, that can handle any arbitrary form or user control, and I was going to cleanly package it up this way (for inclusion in a generic library I maintain), but never did. Too many other things on my plate at the time so I just left things as-is because it works in the sample program. In my real program it would be cleanly done (don't require it though currently). The techniques involved are likely the proper launching point for a professional (bullet-proof) method however so you'll just need to research things further than I did (and create a reusable method). Note BTW that the sample code recursively iterates all child controls from the form on down but for a professional (generic) job, I'd look into ambient properties to make sure there won't be any issues doing it this way (i.e., if some ambient property is applied to a control at the parent level that also affects its child controls, this property may be overridden by a given child control when its own properties are later assigned during recursive iteration - things will probably be ok doing things this way, but I would look into it just to make sure).

Larry
  • 796
  • 6
  • 13