您需要将您的MainWindow的引用传递给其他类以访问其成员。要实现此目的,请在您的MENU-类中创建一个构造函数,该类需要MainWindow-类的实例。此外要更改成员应public,最好的属性,而不是一个领域:
点击查看代码
namespace MMI_WFA
{ public partial class MainWindow : Form { public int Language { get; set; } ... ... } public partial class MENU : Form { private readonly MainWindow window; public MENU(MainWindow window) { this.window = window; } private void cbo_Language_SelectedIndexChanged(object sender, EventArgs e) { this.window.Language = // } }
}
点击查看代码
namespace MMI_WFA
{ public partial class MainWindow : Form { public int Language { get; set; } ... ... } public partial class MENU : Form { private readonly MainWindow window; public MENU(MainWindow window) { this.window = window; } private void cbo_Language_SelectedIndexChanged(object sender, EventArgs e) { this.window.Language = // } }
}