Mirroring Form for RTL languages as Arabic
My previous post Changing UI Language during Runtime showed show you can change the Interface language during runtime. While the information may be sufficient for languages that are written from Left to Right, Languages as Arabic which are written from Right to Left may also require the controls and relevent labels to switch their relative positions or mirror their locations.
When required, this effect can be achieved only by a few lines of code as below.
Private Sub Form_Click()
Form1.RightToLeft = Not Form1.RightToLeft
For Each ctl In Form1
ctl.Left = Form1.ScaleWidth - (ctl.Left + ctl.Width)
ctl.RightToLeft = Not ctl.RightToLeft
Next
End Sub
I have used the code in Click event of the Form so the form mirrors each time when it is clicked…
What the code does is merely changes the “Left” property of the control equal to the gap between its right end and the end of the form. (Also check note “Update” at the bottom).
I have used ScaleWidth property of the form which gives the Client Width of the form as all controls are placed relative to the Client Area. Client area excludes the border, caption and similar spaces where you cannot place your controls.
Want the mirroring to happen for Form caption, Minimize and similar buttons too? Then you will need to use a form with “borderstyle” property set to 0 (None) and then manually add the buttons and clone their functionalities. When done so these buttons will also mirror themselves.
Update : Code to Set RightToLeft property of each control added, which perhaps mirrors the Minimize & Maximize button also. Additionally control as Radio buttons also mirror themselves i.e. the button moves to the right of the label. These are however only visible on Bi-directional Systems (In absence of which I do not stand confirmed on these words). Source : http://www.codeproject.com/csharp/mirrored_controls.asp shows mirroring implementaion in C#.
That’s all!

Hello
Hey Thanks very much…very kind of you to put code and even explain it…its a good quality that one should learn from YOU. Atleast I have Learnt that from YOU..
Your quality is known through your Actions. I guess you are a very kind person by nature. Any way a very big THANKS for this.
regards.
Comment by phil — April 19, 2007 @ 11:08 am
[...] Mirroring Form for RTL languages as Arabic [...]
Pingback by Just Looking Back « Jalaj — May 28, 2007 @ 6:25 am