Using Visual Studio.NET for Internationalization

I l @ ve RuBoard

Visual Studio.NET will manage resources for you and help you to create localized forms and components . Figure 3.4.3 shows the Localizable property being set for a form. Setting this property to true will cause the design time environment to store all the relevant information in the resource file for you.

Figure 3.4.3. Setting the Localizale property.

graphics/0304fig03.gif

The InitializeComponent method for Form1 will now contain code to initialize a resource manager and retrieve any information that might change as the application is transferred between locales from the resources.

As you saw with the handmade example shown in Figure 3.4.2, the physical extents of text strings could change as they are translated, so as well as the text itself, you will find position and size information stored in the resources. InitializeComponent method for Form1 is shown in Listing 3.4.5.

Listing 3.4.5 Form1.cs: InitializeComponent Method
 1: private void InitializeComponent() 2: { 3:    System.Resources.ResourceManager resources = 4:      new System.Resources.ResourceManager(typeof(Form1)); 5:    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); 6:    this.ClientSize = ((System.Drawing.Size)(resources.GetObject("$this.ClientSize"))); 7:    this.Text = resources.GetString("$this.Text"); 8: 9: } 

You can see that the IDE has created a new resource manager on line 3, and lines 6 and 7 retrieve text and client size information from the resources.

When a form is made localizable in this way, all the components you put on the form will also save their text, size, and position information to a resource file. Listing 3.4.4 shows the InitializeComponent method after the addition of a label to Form1.

Listing 3.4.4 Form1.cs: InitializeComponent after Adding a Label
 1: private void InitializeComponent()  2: {  3:  System.Resources.ResourceManager resources =  4:     new System.Resources.ResourceManager(typeof(Form1));  5:  this.label1 = new System.Windows.Forms.Label();  6:  this.label1.Location =  7:     ((System.Drawing.Point)(resources.GetObject("label1.Location")));  8:  this.label1.Size =  9:     ((System.Drawing.Size)(resources.GetObject("label1.Size"))); 10:  this.label1.TabIndex = 11:     ((int)(resources.GetObject("label1.TabIndex"))); 12:  this.label1.Text = resources.GetString("label1.Text"); 13:  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); 14:  this.ClientSize = 15:     ((System.Drawing.Size)(resources.GetObject("$this.ClientSize"))); 16:  this.Controls.AddRange(new System.Windows.Forms.Control[]{ this.label1} ); 17:  this.Text = resources.GetString("$this.Text"); 18: } 

Now the label child component of the form stores its location, size, tab-index, and text in the resources.

I l @ ve RuBoard


C# and the .NET Framework. The C++ Perspective
C# and the .NET Framework
ISBN: 067232153X
EAN: 2147483647
Year: 2001
Pages: 204

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net