Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on what I've understood from your question, I think this is possible if you are trying to call <code>ChangeLanguage(string lang)</code> from the other forms as well.</p> <p>You'll need a <code>Timer</code> added to every <code>Form</code> you would like to use the void on, and TWO variables. The first is a <code>bool</code> which will be used to detect if <code>ChangeLanguage</code> is required to be called within the other TWO forms, and the second is a <code>string</code> which will indicate the language. These TWO variables must be <code>public</code> and <code>static</code> so that they can be controlled through other forms.</p> <h2><strong>Example</strong></h2> <hr> <p><strong><sup> Form1.cs</sup></strong></p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Globalization; namespace NameSpaceGoesHere { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static bool _ChangeLanguage = false; //This will indicate if the void needs to be called public static string _Language = ""; //This will indicate our new language private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { ChangeLanguage("fr-FR"); } private void ChangeLanguage(string lang) { foreach (Control c in this.Controls) { ComponentResourceManager crm = new ComponentResourceManager(typeof(Form1)); crm.ApplyResources(c, c.Name, new CultureInfo(lang)); _Language = lang; //Sets the language to lang _ChangeLanguage = true; //Indicates that the void needs to be called through the TWO other forms as well } } } } </code></pre> <p><strong><sup> Form2.cs</sup></strong></p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Globalization; namespace NameSpaceGoesHere { public partial class Form2 : Form { public Form2() { InitializeComponent(); } public static bool _ChangeLanguage = false; //Required for the third form private void Form2_Load(object sender, EventArgs e) { Timer Timer1 = new Timer(); //Initialize a new Timer object Timer1.Tick +=new EventHandler(Timer1_Tick); //Link its Tick event with Timer1_Tick Timer1.Start(); //Start the timer } private void ChangeLanguage(string lang) { foreach (Control c in this.Controls) { ComponentResourceManager crm = new ComponentResourceManager(typeof(Form1)); crm.ApplyResources(c, c.Name, new CultureInfo(lang)); _ChangeLanguage = true; } } private void Timer1_Tick(object sender, EventArgs e) { if (Form1._ChangeLanguage) //Indicates if ChangeLanguage() requires to be called { Form1._ChangeLanguage = false; //Indicates that we'll call the method ChangeLanguage(Form1._Language); //Call the method } } } } </code></pre> <p><strong><sup> Form3.cs</sup></strong></p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Globalization; namespace NameSpaceGoesHere { public partial class Form3 : Form { public Form3() { InitializeComponent(); } private void Form3_Load(object sender, EventArgs e) { Timer Timer1 = new Timer(); //Initialize a new Timer object Timer1.Tick += new EventHandler(Timer1_Tick); //Link its Tick event to Timer1_Tick Timer1.Start(); //Start the timer } private void ChangeLanguage(string lang) { foreach (Control c in this.Controls) { ComponentResourceManager crm = new ComponentResourceManager(typeof(Form1)); crm.ApplyResources(c, c.Name, new CultureInfo(lang)); } } private void Timer1_Tick(object sender, EventArgs e) { if (Form2._ChangeLanguage) //Indicates if ChangeLanguage() requires to be called { Form2._ChangeLanguage = false; //Indicates that we'll call the method ChangeLanguage(Form1._Language); //Call the method } } } } </code></pre> <p>Thanks, <br>I hope you find this helpful :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload