Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Extremely bizar visible behaviour

$
0
0

Hello all,

I have an application where in a window, on the left there is a tabcontrol, filling 2/3 of the width, and on the left a panel filling the other 1/3.

When the user browses the tabcontrol, I show a particular panel on the right showing some extra info on the tabpage.

To do this, I have made several panels with content, placed them on top of each other and I set the visibility of the panels according to the tabpage that is shown. Now, with one panel in particular, I have some strange behaviour with the visibility.

Let me show you:

When I first open the tabpage, the panel is shown as:

When I leave the tabpage, and return to the previous one for the second time, it looks like this:

Now, because of forum restrictions I can't show you the following, but believe me when I say:

The third time that I visit the tabpage, the panel shows everything but one label. All the next times I visit the tabpage the panel is shown as it should. This behaviour is allways 100% repeatable.

Now, this panel, shown above contains a UserControl, and it is in that usercontrol where the labels are placed. (Almost every brown square is a label).

Now, you wonder, how do you hide it? Well, I listen on the tabcontrol's tabpage changed event and execute the following code:

        private void ShowExtraPanel(TabPage tabPage)
        {
            foreach (var item in _extraPanels)
            {
                if (item.Key != tabPage)
                {
                    HideControl(item.Value); 
                }
            }

            if (_extraPanels.ContainsKey(tabPage))
            {
                ShowControl(_extraPanels[tabPage]);
            }
        }

        private void ShowControl(Control control)
        {
            if (!(control is ImpressiveGuiGuide))
            {
                control.Visible = true;
                control.BringToFront();
                control.Refresh();

                foreach (Control item in control.Controls)
                {
                    ShowControl(item);
                }
            }
        }

        private void HideControl(Control control)
        {
            foreach (Control item in control.Controls)
            {
                HideControl(item);
            }

            control.Visible = false;
        }

As you can see, I hide the controls from in to out, and I show from out to in. I do this because I have a feature that listen's to the Visiblechanged event of some controls, and to make that event fire off good, I need to hide/show the panels this way. (When I would hide the container before hiding the inner label, the label would never fire the visiblechanged event and vice-versa)

An important sidenote also, after I have set the visible to true, it is true (it's not false) I have tested this by showing a messagebox if the visible property was false after setting to true, no messagebox was ever shown.

I also want to make clear that, the code that is executed on the visiblechanged event, does not alter the visibility of the control that fired the events. To make you believe it, only the labels on the left side (the ones with orange text) are being listened for the visibilitychanged event, the labels on the right (which have currently no text) are not being tracked for the visibilitychanged event.

Now, this is getting very long and it's even getting to confuse me! So I hope after reading this you understand what my problem is, what I'm trying to do and if possible comming up with a solution.

Thanks in advance!

PS: I target .NET 4 FULL


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>