Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is Control.Visible = true turns out to be false?

Tags:

c#

winforms

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.

like image 264
amber Avatar asked May 19 '11 16:05

amber


People also ask

Which control is not visible at runtime?

Although code in your control may still run while invisible, you will not be able to interact with the control through the user interface. If you want to create an invisible control that still responds to user input (for example, mouse clicks), you should create a transparent control.

Which of the property in a control helps to return or set a value indicating whether an object is visible or hidden?

Control. Visible Property (System.

How do you make a form visible in C#?

In C#, you will have to create all but the MainForm. // in a buttonClick on Form1 Form2 f2 = new Form2(); f2. Show(); This will create a new instance each time you click the button.


1 Answers

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

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 = true and THEN the child control(s).

like image 133
Sani Singh Huttunen Avatar answered Sep 19 '22 15:09

Sani Singh Huttunen