tags:

views:

33

answers:

1

Using WinForms and C#:

I have a panel that contains a groupbox, some checkboxes, and textboxes. This panel is not always visible. Depending on user selections I show the panel. However, the screen is large enough that it requires scrollbars depending on your screen resolution.

Does anyone know why the panel would move based on the AutoScrollPosition? I cannot find why it jumps around. I am not changing the location anywhere in the code. I have found a work around that I have listed below. But it would be nice to understand why it is happening.

           if (m_PanelHoist.Location.Y != m_GroupBoxDrag.Location.Y)
           {
              Point point = m_PanelHoist.Location;
              point.X += AutoScrollPosition.X;
              point.Y += AutoScrollPosition.Y;
              m_PanelHoist.Location = point;
           }
+1  A: 

You are using this.AutoScrollPosition. Which suggests that the panel is getting scrolled by the form. That's entirely normal, all child controls inside the form are subject to getting scrolled, including your panel. Your code snippet indeed compensates for that.

By design.

Hans Passant
I guess I'm not following? Why would only the panel get scrolled and not the other groupboxes (and other controls) that are at the same level in the tree? What is the deciding factor in wither the control is scrolled by the form or not?
Billy
The Parent counts, set when the control is added to the container's Controls collection. You'd have to look in the InitializeComponent() method to see what container has what control. Not getting the group boxes scrolled could only happen if the scroll bar is shown by some other control. Maybe a docked panel?
Hans Passant
Ok I think I finally understand now. After reading and playing some more I see what you are saying. Thanks for the help Hans!
Billy