• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

interface mirroring of bilingual windows forms

hi experts..

I have a windows form which is bilingual and based on the language the user selects the layout of the form should change. I change the direction property of the form from "left to right" to "right to left" but it changes the layout of each control.. i need the whole form to mirror itself so it moves the controls that are on the left side of the form,to the right side and vice versa.. based on the language.
I'm using .NET 1.1
Is there an effective way to accomplish this using VB.NET..??
0
mirmansoor
Asked:
mirmansoor
  • 2
1 Solution
 
nickhoggardCommented:
Hi,

Not sure if there is an easier way built into .NET, but the following seemed to work in a quick test project I created:


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each ctrl As Control In Me.Controls
            SwitchControls(ctrl)
        Next
    End Sub

    Private Sub SwitchControls(ByVal ctrl As Control)
        For Each objControl As Control In ctrl.Controls
            SwitchControls(objControl)
        Next
        ctrl.Left = ctrl.Parent.ClientRectangle.Width - ctrl.Left - ctrl.Width
    End Sub

The general idea is to recursively check all controls on the form, and mirror them to the opposite side.

Hope this helps

Cheers

Nick
0
 
nickhoggardCommented:
Just to followup, I wrote that in .NET 2.0, but I dont think there is anything there that is not in 1.1.  

Nick
0
 
MascoloCommented:
Using .NET 2.0 also provides a better solution which may be worth the cost in upgrading to against the amount of time you potentially need to write something similar to above. That is in .NET 2.0 you can set a form or container RightToLeft property which then alters all child controls RightToLeft property too.

The following code alters a whole form (and all its labels, buttons etc) when a button is pressed

             frmMain.RightToLeft = Windows.Forms.RightToLeft.Yes

You can also pass '...+ MsgBoxStyle.MsgBoxRtlReading) into the MessageboxStyle so that dialogs also behave in this manor too. This also includes swapping the control boxes and form captions too, all in literally one line of code!
0
 
Jeff CertainCommented:
I would imagine that the culture properties (you *are* using culture for you localization, right?) would include a RightToLeft indicator as well....

Specifically, CultureInfo.TextInfo.IsRightToLeft will tell you how you need to display the text.

As Mascolo pointed out, however, the control RightToLeft property in 2.0 specific.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now