Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my C# 4.0 Forms program I am trying to approximate a list box with labels and buttons on each item.
I am using a main panel, with autoscroll = true, and programmatically adding sub panels to the main panel.
The sub panels are almost as wide as the main panel and located below each other so that the vertical scroll is used to see all the sub panels (like a list box).
Each time the main panel is shown (visibility = true) the Panel.Contols.Clear function is called then sub panels are added as needed. This works fine the first time!
Problem is if the main panel is scrolled down at all when its visibility is set to false next time the main panel is shown the sub panels that were scrolled off the top will not show.
I have tried setting autoscroll to false then back to true.

Chris
Posted

As far as I can see, Autoscroll has nothing to do with this.

Try enumerating the Controls collection and setting the Visible property on all the sub-panels to True.
 
Share this answer
 
I added setting Vericalscroll.Value = 0
So code goes something like this.

myScrollablePanel.Vericalscroll.Value = 0; // this is the fix
myScrollablePanel.Controls.Clear();
for(...)
{
...
myScrollablePanel.Controls.Add(m_MySubPanels[i]);
...
}

Now always shows top of myScrollablePanel, the vertical scroll if appropriate and my upper sub panels

Note: Each time myScrollablePanel is made visible it has a new set of controls on it.

Thanks
Chris
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900