0

I am new to c#. I am creating a program with Multilanguage option. Every thing works fine with both English and Arabic languages. Language is changing properly. when I try to change layout property of dashboard from right to left and start my program to check, Program window disappears without leaving any traces.

When I set "right to left layout" property to true program works fine but don't change layout. When I set "Right to left" property to yes, program change layout in designer mode. But when I start program to check on selecting Arabic Language program window disapears without leaving any trace.

Note: "Right to left" and "Right to left layout" are different properties.

using System;
using System.Threading;
using System.Windows.Forms;

namespace POS.screens
{
    public partial class dashboard : Form
    {
        public dashboard()
        {
            InitializeComponent();
        }

        private void addProductToolStripMenuItem_Click(object sender, EventArgs e)
        {
            add_product addProduct = new add_product();
            addProduct.ShowDialog();
        }

        private void catagoriesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            catagories Catagories = new catagories();
            Catagories.ShowDialog();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            sell myForm = new sell();
            myForm.TopLevel = false;
            myForm.AutoScroll = true;
            myForm.FormBorderStyle = FormBorderStyle.None;
            this.ExtForm.Controls.Add(myForm);
            myForm.Show();
        }

        private void LanguageComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch(LanguageComboBox.SelectedIndex)
            {
                case 0:
                    Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
                    break;

                case 1:
                    Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ar-DZ");
                    break;

            }
            this.Controls.Clear();
            InitializeComponent();
        }

    }
}

Thanks in advance

Lance U. Matthews
  • 15,725
  • 6
  • 48
  • 68
Wahab
  • 13
  • 3
  • are you running this under debug in visual studio? Doesnt it say anyhing? How about in the output pane? – pm100 Jan 15 '22 at 23:45
  • Yes. I am running it under debug in visual Studio. I checked my code by creating a new form and inserted coding blocks one by one in it. It started working. But now problem is that when I change language from English to Arabic it change layout from right to left. And When I try to change language From Arabic to English back It don't work. It is showing following error Exception thrown at 0x74A81A6E (comctl32.dll) in POS.exe: 0xC0000005: Access violation reading location 0x00200038. – Wahab Jan 16 '22 at 00:13
  • If the output windows doesn't show anything, you could try the eventviewer – Jeroen van Langen Jan 16 '22 at 00:13
  • @JeroenvanLangen Please check my comment. what type of error is this and how can I fix it? It started working. But now problem is that when I change language from English to Arabic it change layout from right to left. And When I try to change language From Arabic to English back It don't work. It is showing following error Exception thrown at 0x74A81A6E (comctl32.dll) in POS.exe: 0xC0000005: Access violation reading location 0x00200038. – Wahab Jan 16 '22 at 00:19
  • An "Access violation" is caused by writing to memory with bad pointers. At least memory not allocated by your program. In c# it doesn't happen that fast, so it will probably be in unmanaged code, perhaps when loading the new culture settings or rendering the right-to-left font. Just speculation. I don't think you could not solve it. A bug report sounds like a good idea. – Jeroen van Langen Jan 16 '22 at 00:50
  • Not clear how you do the localization part. You should design the UI using the default language (English), then enable the `Form.Localizable` property, and select the new language from the `Form.Languages` collection. Then, apply the RTL layout and modify the UI (Menus, Labels, Text....etc) to apply the new language. You need to `Application.Restart();` to recreate the handles and apply the RTL style. [Set the current culture](https://stackoverflow.com/a/51603215/14171304) before `Application.Run(mainForm);`. – dr.null Jan 16 '22 at 01:48
  • [Walkthrough: Localizing Windows Forms](https://learn.microsoft.com/en-us/previous-versions//y99d1cd3(v=vs.85)?redirectedfrom=MSDN). – dr.null Jan 16 '22 at 01:50
  • your assumption is the cause is localization, it might not be. Do you have any unmamaged code in your app? YOu could have undefined behavior there that works sometimes, but not others – pm100 Jan 16 '22 at 18:03
  • I should note that [I tagged this question](https://stackoverflow.com/revisions/70726291/2) as [tag:.net] just to get in front of eyeballs for a major underlying technology. Please retag it as [tag:.net-core] if appropriate. Including the version number of either framework in the question may be significant, too. – Lance U. Matthews Jan 17 '22 at 10:08

0 Answers0