I have a C# WinForms project that’s very wizard like in its functionality. The individual steps live on a class called StepPanel, which inherits from the Panel control, within the form and those panels are organized in an array.
What I’ve run into is that when UpdateUI() is called and walks the array, adjusts the wizards step title text for the current step, it makes sure that all of the inactive steps are hidden, and ensures that the active step is visible, in the right spot, and is the right size.
Here’s the code:
private void UpdateUI()
{
// If the StepIndex equals the array length, that's our cue
// to exit.
if (StepIndex == Steps.Length)
{
Application.Exit();
return;
}
for (var xx = 0; xx < Steps.Length; xx++)
{
if (xx == StepIndex)
{
if (!String.IsNullOrEmpty(Steps[xx].Title))
{
LabelStepTitle.ForeColor = SystemColors.ControlText;
LabelStepTitle.Text = Steps[xx].Title;
}
else
{
LabelStepTitle.ForeColor = Color.Red;
LabelStepTitle.Text =
Resources.UiWarning_StepTitleNotSet;
}
}
else
{
Steps[xx].Visible = false;
}
}
Steps[StepIndex].Top = 50;
Steps[StepIndex].Left = 168;
Steps[StepIndex].Width = 414;
Steps[StepIndex].Height = 281;
Steps[StepIndex].Visible = true;
SetNavigationButtonState(true);
}
When everything is said and done, Steps[StepIndex].Visible == false.
I’m still perplexed by this behavior because I was working less than 30 minutes ago.
If you set a parent/container control to
Visible = falsethen setting any child controls toVisible = truewill have no effect what so ever. TheVisibleproperty of the child control will still befalse.I don’t know if it’s what happens in this case since I don’t know the structure of the controls but it seems to be a likely scenario.
To solve this you need to first set the parent/contianer control to
Visible = trueand THEN the child control(s).