根据我从您的问题中了解到的情况,我认为如果您也尝试ChangeLanguage(string lang)
从其他表格中拨打电话,这是可能的。
您需要Timer
添加到每个Form
您想使用 void 的变量和两个变量。第一个是bool
用于检测是否ChangeLanguage
需要在其他两种形式中调用的 a,第二个是string
用于指示语言的 a。这两个变量必须是public
和static
才能通过其他形式来控制。
例子
Form1.cs
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
}
}
}
}
Form2.cs
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
}
}
}
}
Form3.cs
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
}
}
}
}
谢谢,
我希望你觉得这有帮助:)