Switch Windows form controls back from RTL?

B

Byron

I'm making my first attempt at localizing a Windows Form application using
both an TLR and RTL language and I'm having some issues.

I created my form in the Default language (en-US), layed the controls out,
changed the language to ar-SA - an RTL language - and set the
RightToLeftLayout and RightToLeft to true for the form and RightToLeft to
true for the controls.

I also moved some controls from the right to the left side of the screen, so
the default an RTL language forms have a different layout.

When I run the application, starting it in the default LTR language, and
change the culture while it is running, my comboboxes change from LTR to RTL,
but the controls I moved in the RTL versions of the form do not switch. When
I change back to the LTR language there is no layout change, though the text
correctly changes back to the default language when I use ApplyResources().

Is there something else I need to do to switch back to LTR layout? Why
aren't my controls changing location as they should when I switch cultures?
The two language-specific forms looks correct in the IDE.

Thanks in advance for any help you can offer.
 
P

Peter Duniho

Byron said:
[...]
When I run the application, starting it in the default LTR language, and
change the culture while it is running, my comboboxes change from LTR to RTL,
but the controls I moved in the RTL versions of the form do not switch. When
I change back to the LTR language there is no layout change, though the text
correctly changes back to the default language when I use ApplyResources().

Is there something else I need to do to switch back to LTR layout? Why
aren't my controls changing location as they should when I switch cultures?
The two language-specific forms looks correct in the IDE.

Thanks in advance for any help you can offer.

I admit, not something I know much about. But, I can at least point out
that your question should be more specific. A concise-but-complete code
example would be especially helpful.

In the meantime, there's at least one point of clarification you should
make: are you creating new instances of the controls after changing the
culture setting? Or are you expecting the layout to update dynamically
when the culture changes?

Because the latter, I _definitely_ would not expect to work. But I
would expect new instances to follow the current culture setting,
whatever it is at the time the form or control is instantiated.

Pete
 
B

Byron

I'm not creating new instances of the controls. However, the comboboxes do
switch from the default (en-US) LTR layout to the RTL layout of the ar-SA
culture. They do NOT switch back to LTR when I switch back to en-US.

Peter Duniho said:
Byron said:
[...]
When I run the application, starting it in the default LTR language, and
change the culture while it is running, my comboboxes change from LTR to RTL,
but the controls I moved in the RTL versions of the form do not switch. When
I change back to the LTR language there is no layout change, though the text
correctly changes back to the default language when I use ApplyResources().

Is there something else I need to do to switch back to LTR layout? Why
aren't my controls changing location as they should when I switch cultures?
The two language-specific forms looks correct in the IDE.

Thanks in advance for any help you can offer.

I admit, not something I know much about. But, I can at least point out
that your question should be more specific. A concise-but-complete code
example would be especially helpful.

In the meantime, there's at least one point of clarification you should
make: are you creating new instances of the controls after changing the
culture setting? Or are you expecting the layout to update dynamically
when the culture changes?

Because the latter, I _definitely_ would not expect to work. But I
would expect new instances to follow the current culture setting,
whatever it is at the time the form or control is instantiated.

Pete
.
 
P

Peter Duniho

Byron said:
I'm not creating new instances of the controls. However, the comboboxes do
switch from the default (en-US) LTR layout to the RTL layout of the ar-SA
culture. They do NOT switch back to LTR when I switch back to en-US.

As I said, if you're not creating new instances, I would not expect the
actual layout of the form to change.

As for the ComboBox instances, I'm still not really clear on what you're
describing, but if you mean that the presentation within those ComboBox
instances does change from LTR to RTL at runtime when you change the
current culture, but does not change back from RTL to LTR when you
change the culture _again_, that seems like a bug to me.

Whether it's a bug in your code or in .NET, I can't say. Partly because
you haven't provided a concise-but-complete code example that reliably
demonstrates the problem, and partly because it's not really an area of
..NET I'm that familiar with in the first place.

Someone may yet come along and see your question who knows exactly what
you're talking about and can provide some specific advice. That could
happen as late as some time next week, since of course many people are
on holiday at the moment. If no such advice appears, you may want to
consider providing an actual concise-but-complete code example that
reliably demonstrates the problem, so as to better facilitate the
problem description as well as making it easier for people unfamiliar
with the text-direction support in .NET to still consider your question.

It's also possible that somewhere out there, there's a
localization-specific newsgroup where questions like this are
specifically on-topic and where you'd get a much quicker,
better-informed reply.

Pete
 
K

kndg

Byron said:
I'm making my first attempt at localizing a Windows Form application using
both an TLR and RTL language and I'm having some issues.

I created my form in the Default language (en-US), layed the controls out,
changed the language to ar-SA - an RTL language - and set the
RightToLeftLayout and RightToLeft to true for the form and RightToLeft to
true for the controls.

I also moved some controls from the right to the left side of the screen, so
the default an RTL language forms have a different layout.

When I run the application, starting it in the default LTR language, and
change the culture while it is running, my comboboxes change from LTR to RTL,
but the controls I moved in the RTL versions of the form do not switch. When
I change back to the LTR language there is no layout change, though the text
correctly changes back to the default language when I use ApplyResources().

Is there something else I need to do to switch back to LTR layout? Why
aren't my controls changing location as they should when I switch cultures?
The two language-specific forms looks correct in the IDE.

Thanks in advance for any help you can offer.

Hi Byron,

I had tried base on your above description but it work correctly. Maybe
you should post your code so others may have more information to help.
Here is my half complete code. I add the menu (for selecting the
language), label, textbox and combobox and it work as intended.

public partial class Form1 : Form
{
private ToolStripMenuItem selectedLanguages;

public Form1()
{
InitializeComponent();

selectedLanguages = englishToolStripMenuItem;
}

private void englishToolStripMenuItem_Click(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
RightToLeft = RightToLeft.No;
RightToLeftLayout = false;
ChangeResource();
ToggleLanguage((ToolStripMenuItem)sender);
}

private void arabicToolStripMenuItem_Click(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo("ar-SA");
RightToLeft = RightToLeft.Yes;
RightToLeftLayout = true;
ChangeResource();
ToggleLanguage((ToolStripMenuItem)sender);
}

private void ChangeResource()
{
var crm = new ComponentResourceManager(typeof(Form1));

foreach (Control control in Controls)
{
crm.ApplyResources(control, control.Name);
}
}

private void ToggleLanguage(ToolStripMenuItem menuItem)
{
menuItem.Checked = true;
selectedLanguages.Checked = false;
selectedLanguages = menuItem;
}
}

Happy Holiday!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top