问题
I would like to create panels with detailed information regarding an item (including a thumbnail image on the left hand side) and then add these to a scrollable list. Much like how iTunes on the iPhone displays the lists of applications available.
I have done some searching but have thus far been unable to find any assistance.
Does anyone have any ideas or links to samples they would like to share with me.
Thanks in advance, Rob
回答1:
In sum, the following creates a series of panels within a container that scroll in and out of view using a vertical scroll bar.
You did not list ASP.NET in your tags, so I assume this is Windows form-based, not web based. I'll get you started:
- Create a panel called
GrandChildPanel
. Inside it, put an image box on the left side and labels with the information you want to display next to the image. This panel will be duplicated for every item (i.e., iTunes song). - Put that panel inside another, equal-width, equal-height panel called
ChildPanel
. - Create another panel called
ParentPanel
and set its width to the size of the other panels plus enough room for a vertical scroll bar. Set the height equal to however tall you want the scrollable area to be. - Put
ChildPanel
in the top-right corner ofParentPanel
and add a vertical scroll bar to the far right edge ofParentPanel
. Set the scroll bar's height to takeup the entire height ofParentPanel
. - You probably want to add a border to
ParentPanel
to show its boundaries. - You also probably want to add a 1 or 2 pixel line across the bottom of your
GrandChildPanel
to show where the panel ends.
That's the setup. Here are the requirements for your code: Each time you 'add an item to the list' (e.g., every song in your iTunes list), you do the following:
- Clone the
GrandChildPanel
. - Assign the clone to be a child of the
ChildPanel
. - Set the clone's
Top
to be equal to the previous clone'sTop
plus itsHeight
. - Set
ChildPanel
'sHeight
equal to any givenGrandChildPanel
's height multiplied by the number of clones. - Set the scroll bar's maximum value to equal
ChildPanel
's height.
Now, all you have to do to make this scrollable is perform the following on the scrolling or changing events of the vertical scroll bar: Set ChildPanel
's Top
to be equal to the verticle scroll bar's value ("position") multiplied by -1
.
来源:https://stackoverflow.com/questions/7163634/c-sharp-list-of-panels