When does Control.Visible = true turn out to be false?

I have a C # WinForms project that is very magical, as in its functionality. Separate steps are performed in a class called StepPanel, which is inherited from the Panel control, inside the form, and these panels are organized into an array.

What I came across is that when UpdateUI () is called and moves through the array, it adjusts the title text of the wizard step for the current step, it ensures that all inactive steps are hidden, and ensures that the active step is displayed in the right place and has right size.

Here is the code:

private void UpdateUI() { // If the StepIndex equals the array length, that 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 all is said and done, Steps [StepIndex] .Visible == false.

I am still perplexed by this behavior because I worked less than 30 minutes ago.

+6
source share
3 answers

If you set the parent / container control to Visible = false , then setting any child controls to Visible = true will have no effect. The Visible property of the child control will be false .

I do not know if this will happen in this case, since I do not know the structure of the controls, but it seems to be a likely scenario.

To solve this problem, you need to first set the parent / contianer control to Visible = true and the THEN child control.

+16
source

if (xx == StepIndex)

There will be only truth and the end of the cycle, if I did not miss something.

0
source

There are several possibilities. When you attach the debugger in the line:

 SetNavigationButtonState(true); 

is there Steps[StepIndex].Visible == true ? If so, make sure that StepIndex is actually the index you expect (not turned off by 1, but not reflect the "previous" step). If you make sure that the correct step is set to true, you should update it somewhere else.

if Steps[StepIndex].Visible == false immediately after you set the value to true, then either the getter in the Visible property is returned based on some calculation, or an event is triggered that changes it to false.

NTN.

0
source

Source: https://habr.com/ru/post/888559/


All Articles