あなたの質問から私が理解したことに基づいてChangeLanguage(string lang)
、他のフォームからも電話をかけようとしている場合、これは可能であると思います.
void を使用するTimer
すべての変数と 2 つの変数を追加する必要があります。Form
1 つ目は が他の 2 つのフォーム内で呼び出される必要があるbool
かどうかを検出するために使用される で、2 つ目は言語を示す です。これらの 2 つの変数は、他の形式で制御できるようにする必要があります。ChangeLanguage
string
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
}
}
}
}
ありがとう、
これがお役に立てば幸いです:)