Wednesday, February 09, 2005

Globalization Workshop

I finished conducted the first software globalization and localization workshop yesterday. The presentations, lab walkthroughs and code samples used during the workshop can be found here.

One addendum to the above content is designing WinForms application for Middle-Eastern market (for use with BiDi scripts). To fully support RTL (Right To Left) locales such as Arabic, you need to set the RightToLeft property of your form to Yes. In addition you need to enable "mirroring". Unfortunately there is no System.Windows.Forms property that corresponds to mirroring. But you can easily achieve it by overriding the CreateParams property:


Protected Overrides ReadOnly Property CreateParams()As
System.Windows.Forms.CreateParams
    Get
        'Retrieve the CreateParams class to change the style
        Dim CP As System.Windows.Forms.CreateParams
        
        CP = MyBase.CreateParams
        'If the control needs RTL add these styles
        If _Mirrored Then
            CP.ExStyle = CP.ExStyle Or &H400000 Or &H100000
        End If
        Return CP
    End Get
End Property





In C# you do the same as:


protected override CreateParams CreateParams
{
 get
 {
  CreateParams cp = base.CreateParams;
  if(_Mirrored)
  {
    CreateParams cp = base.CreateParams;
    cp.ExStyle = cp.ExStyle | 0x400000 | 0x100000;
  }
 return cp;
 }
}




*minor modifications made to the code on 6 May 05, thanks Anonymous!

This is what your form would appear like once it is "mirroring" correctly:

RTLForm.

Here some links that are must visit if software globalization/localization is your cup of tea:

3 comments:

Anonymous said...

What happens to the controls themselves? I assume that they get mirrored too. But the point I was not sure about is what happens to a label-textbox combination? It may not be a simple thing to mirror that.

Deepak said...

Depends.. :)

For simple controls like Label and TextBox you can get away without doing any explicit mirroring work. For others you might need to implement a custom version (not too hard). Take a look at: http://www.microsoft.com/middleeast/msdn/arabicsupp.aspx one of the things that they do is implement a mirror-aware Tree control.

Anonymous said...

Minor modification to the C# sample code.

protected override CreateParams CreateParams
{

get
{
CreateParams cp = base.CreateParams;
if(_Mirrored)
{
cp.ExStyle = cp.ExStyle | 0x400000 | 0x100000;

}

return cp;
}
}

For some reason when I do this the standard C# toolbar is completely hosed. Has anyone else seen this?