Restore mdi children after Controls.Clear

20 Views Asked by At

I have Form1 which is MdiParent and Form2 which is MdiChild. In Form1 I have sidebar which has combo box that contains language names, and buttons which switches between mdi children. When value of combo box changes, it executes this code:

private void LanguageSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            CultureInfo culture;
            string langText = LanguageSelect.Text;
            if (langText == "Russian" || langText == "Русский")
            {
                culture = new CultureInfo("ru");
            }
            else
            {
                culture = new CultureInfo("en");
            }
            currentCulture = culture;

            Thread.CurrentThread.CurrentUICulture = culture;
            this.Controls.Clear();
            InitializeComponent();
        }

Code above works fine, it changes language as expected, but after it, buttons that select specific mdi children, stopped working, it just doesn't do anything. How can I fix it? Below is code that is executed when that buttons pressed:

        private void AboutBtn_Click(object sender, EventArgs e)
        {
            if (aboutForm == null)
            {
                aboutForm = new AboutForm();
                aboutForm.FormClosed += AboutForm_Closed;
                aboutForm.MdiParent = this;
                aboutForm.Dock = DockStyle.Fill;
                aboutForm.Show();
            }
            else
            {
                aboutForm.Activate();
            }

        }

        private void AboutForm_Closed(object sender, FormClosedEventArgs e)
        {
            aboutForm = null;
        }

I tried to recreate mdi child and execute it's show method, tried just executing this.ActiveMdiChild.Activate() this.ActiveMdiChild.Refresh() this.ActiveMdiChild.Update()

but not result. I would like mdi child to remain on its place when language changed.

Thanks for attention.

0

There are 0 best solutions below