Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use a base class, that holds a static event of "LanguageChanged", and a function to trigger it. If all your forms are derivative class of that base class, the event could be handled within it. Something like:</p> <pre><code>public partial class Form1 : BaseLanguageForm { public Form1() { InitializeComponent(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedItem.ToString() == "English") { this.TriggerLanguageChange("en"); } else if (comboBox1.SelectedItem.ToString() == "Spanish") { this.TriggerLanguageChange("es-ES"); } else if (comboBox1.SelectedItem.ToString() == "French") { this.TriggerLanguageChange("fr-FR"); } } } /// &lt;summary&gt; /// The event that should be passed whenever language needs to be changed /// &lt;/summary&gt; public class LanguageArgs:EventArgs { string _languageSymbol; /// &lt;summary&gt; /// Gets the language symble. /// &lt;/summary&gt; public string LanguageSymbol { get { return _languageSymbol; } } /// &lt;summary&gt; /// Initializes a new instance of the &lt;see cref="LanguageArgs"/&gt; class. /// &lt;/summary&gt; /// &lt;param name="symbol"&gt;The symbol.&lt;/param&gt; public LanguageArgs(string symbol) { this._languageSymbol = symbol; } } /// &lt;summary&gt; /// A base class that your class should derivative from /// &lt;/summary&gt; public class BaseLanguageForm:Form { /// &lt;summary&gt; /// Triggers the language change event. /// &lt;/summary&gt; /// &lt;param name="languageSymbol"&gt;The language symbol.&lt;/param&gt; protected void TriggerLanguageChange(string languageSymbol) { if (Form1.onLanguageChanged != null) { LanguageArgs args = new LanguageArgs(languageSymbol); Form1.onLanguageChanged(this, args); } } /// &lt;summary&gt; /// This should be triggered whenever the combo box value chages /// It is protected, just incase you want to do any thing else specific to form instacne type /// &lt;/summary&gt; protected static event EventHandler&lt;LanguageArgs&gt; onLanguageChanged; /// &lt;summary&gt; /// This will be called from your form's constuctor /// (you don't need to do anything, the base class constuctor is called automatically) /// &lt;/summary&gt; public BaseLanguageForm() { //registering to the event BaseLanguageForm.onLanguageChanged += new EventHandler&lt;LanguageArgs&gt;(BaseLanguageForm_onLanguageChanged); } /// &lt;summary&gt; /// The function that was regidtered to the event /// &lt;/summary&gt; /// &lt;param name="sender"&gt;The sender.&lt;/param&gt; /// &lt;param name="e"&gt;The e.&lt;/param&gt; void BaseLanguageForm_onLanguageChanged(object sender, LanguageArgs e) { string lang = e.LanguageSymbol; foreach (Control c in this.Controls) { ComponentResourceManager crm = new ComponentResourceManager(typeof(Form1)); crm.ApplyResources(c, c.Name, new CultureInfo(lang)); } } } </code></pre>
    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.
    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