此应用程序包含2个窗口;所有者窗口中有标签,分配了indicator1
名称。方法IndicatorOn()
必须更改标签的外观,但只有在从同一窗口(IndicatorOn()
)调用Main Window
时才会发生,如果从其他窗口调用它,则会发生零效果我的应用。我试图调试 - 一切似乎都没问题:程序成功进入case 1
阻止并退出,只是与indicator1
相关的命令被忽略了......
public partial class MainWindow : Form {
public MainWindow() {
InitializeComponent();
}
private void MainWindow_Load(object sender, EventArgs e) {
ChildWindow childWindow = new ChildWindow();
childWindow.Owner = this;
childWindow.Show();
}
public void IndicatorOn (byte indicatorNumber) { // assume that it cout is small
switch (boothNumber) {
case 1:
indicator1.ForeColor = System.Drawing.Color.Black;
indicator1.BackgroundImage = ExamopleProject.Properties.Resources.IndicatorActive;
indicator1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
break;
}
// ....
}
}
public partial class ChildWindow : Form {
MainWindow mainWindow;
public ChildWindow() {
InitializeComponent();
mainWindow = new MainWindow();
}
private void Button1_Click(object sender, EventArgs e) {
}
}