I want to get the chosen language from the Form1 combobox and enable other forms to view the language. The combobox has approximately 20 languages, so yes quite a few you could say! I have a method called ComboBoxLang_SelectedIndexChanged (occurs when the language in the combobox is changed):
// Works fine in Form1.cs
private void ComboBoxLang_SelectedIndexChanged(object sender, EventArgs e)
{
string selectedItem = this.comboBoxLang.GetItemText(this.comboBoxLang.SelectedItem);
comboBox2.Items.Clear();
if (selectedItem == "English")
{
ToEnglish();
}
else if (selectedItem == "French")
{
ToFrench();
}
// And so on...
}
For the moment, to test that it works I just want to display a message of the language chosen in another form. I have researched and have tried multiple ways, but obviously I am going wrong somewhere! I thought may be using the get and set method would be most useful but I'm really not sure. I want the MessageBox to say "English" or whatever the selection is.
Another example, I know that using
Form1 f1 = new Form1();
... in the second form that is trying to retrieve the value is incorrect as it just gets the hard-coded text and I just want the actual value that has been entered. So I wasn't sure if I should use
private Form1 f1;
... in the second form instead. I am really confused.
I know this is a common question but I can't seem to find a solution.