由于某种原因,以下代码不会在运行时更新选项卡上显示的文本:
tabControl.TabPages[i].Text = newProps.plot_title;
//I tried these too but still no cigar
//tabControl.TabPages[i].Refresh();
//tabControl.Refresh();
我错过了一些明显的东西吗?
编辑:这是一个单线程WinForms应用程序。所以更新是在GUI线程上完成的。选项卡的内容更新没有任何问题。只有标签文本无法更新。完整代码:
/// <summary>
/// Show a dialog box to display and allow user to modify the plot's properties
/// </summary>
public void EditPlotProperties()
{
Graph_Properties currProps = plotControls[tabControl.SelectedIndex].cube.graphProps;
PlotProperties propsWindow = new PlotProperties(currProps);
if (propsWindow.ShowDialog(this) == DialogResult.Cancel)
return;
Graph_Properties newProps;
propsWindow.GetGraphProperties(out newProps);
if (newProps.IsEqual(currProps))
return;
LogFile.Instance.Write(MethodBase.GetCurrentMethod().ToString(),
"New plot properties:" + newProps.ToString());
for (int i = 0; i < numPlots; i++)
{
if (i == tabControl.SelectedIndex || newProps.apply_all_plots)
{
plotControls[i].cube.graphProps.plot_title = newProps.plot_title;
plotControls[i].cube.graphProps.x_label = newProps.x_label;
plotControls[i].cube.graphProps.lower_x = newProps.lower_x;
plotControls[i].cube.graphProps.upper_x = newProps.upper_x;
plotControls[i].cube.graphProps.y_label = newProps.y_label;
plotControls[i].cube.graphProps.lower_y = newProps.lower_y;
plotControls[i].cube.graphProps.upper_y = newProps.upper_y;
plotControls[i].cube.graphProps.z_label = newProps.z_label;
plotControls[i].cube.graphProps.lower_z = newProps.lower_z;
plotControls[i].cube.graphProps.upper_z = newProps.upper_z;
plotControls[i].cube.graphProps.plot_size = newProps.plot_size;
plotControls[i].cube.graphProps.channels = newProps.channels;
plotControls[i].render();
// TODO: for some reason this doesn't appear to update the tab text
tabControl.TabPages[i].Text = newProps.plot_title;
tabControl.Refresh();
unsavedChanges[i] = true;
}
}
}