I'm writing a custom control that contains a list of items (child controls) that resize horizontally to fit the width of the control. If there are lots of items (or the control is resized so that it is not tall enough vertically) then a vertical scroll bar is necessary; but when the vertical scroll bar appears, the child controls are suddenly too wide, which causes a horizontal scroll bar to appear.
What's the proper way to guarantee that a horizontal scroll bar does not appear when it is not necessary, given that I am controlling the control placement manually (not relying on AnchorStyles)? (Note: I can't control the VScroll property manually because I'm on Compact Framework; and if an item's minimum width is wider than the client area then a horizontal scroll bar will be required legitimately.)
What I did in a similar situation was after every time I added an item to the list I detected whether the scroll bar was visible or not and adjusted my the width manually.
What I did to detect whether the scroll bar was showing was either:
Test for the WS_VSCROLL was set on the control via P/Invoke via GetWindowLong().
Scan the control's children for a vertical scroll bar control.
It depends on how the control handles scroll bars as to which one is correct.
Also this was on Windows, not in the CF so I'm not sure if this will work exactly the same way.
Take the width of the vertical scrollbar into account when calculating the required width for your child controls:
System.Windows.Forms.SystemInformation.VerticalScrollBarWidth
Related
My Project is currently in C# Winforms.
I have a custom control that I am inserting on a flow layout panel.
I also have a header that fits above the Flow Layout.
I would like the flowlayout to scroll on the vertical axis while the whole panel scrolls along the horizontal axis.
The problem I am having is that the flowlayout when autoscroll is set to true makes use of both horizontal and vertical scroll
I need the header to scroll horizontally at the same time as the flowlayout but not show its own horizontal scrollbar. I also need the header to stay at the top of the Panel when the flowlayout scrolls vertically.
Thanks for the help
I have been trying out different combinations of autoscroll, wrapcontents and Autosize.
I'm making an instant messaging application in C#. The problem that I'm facing right now is that for the contacts list I've made a custom control extendinguserControl, which contains aFlowLayoutPanel`.
That panel will contain a list of userControls. I want to customize the VscrollBar, but no chance (not possible). Instead I have this genius idea to hide the VscrollBar from the FlowLayoutPanel, and make simple buttons (UP and down events). For this everything worked like a charm, but when I tried to hide the VscrollBar by making the property autoScroll = false , the buttons stopped working.
How can I hide the VscrollBar?
If you want to hide the the vertical bar, there are some possible solutions. ..
You could make an event for resize, controls add, controls remove and set all the child controls' width to flowlayoutpanel.width -20
You could add a panel to the flowlayoutpanel and set it to autosize and make the panels may width to flowlayoutpanel.width-20.
You could check if the width of the flowlayoutpanel is bigger than its real width (means vscrollbar appeared) , and resize the children that it'll/ld hide again
and if you are sure that your controls are smaller than the flowlayoutpanel's width, you simply could create a panel which covers the vertical bar. (use .BringToFront() to put it before the flowlayoutpanel's scrollbar)
I hope that I understood and perhaps have solved the problem
I have a control in C# that I want to AutoScroll. But when the scroll bar appears, it overlays part of the control. Is there any way I can make the control resize its contents to accomodate the scroll bar? This isn't a custom control; it's a standard .NET TabPage control. I really don't want to have to wire up a scroll bar manually...
I was able to work around this by adding a Panel control to the control I wanted to scroll, with a 12px right margin to accommodate the scrollbar. Not sure how this will look on high DPI settings, but it can always be tweaked.
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
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 of ParentPanel and add a vertical scroll bar to the far right edge of ParentPanel. Set the scroll bar's height to takeup the entire height of ParentPanel.
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's Top plus its Height.
Set ChildPanel's Height equal to any given GrandChildPanel'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.
C# WinForms: if I want to have the location of a control on a panel regardless of where is the Vertical scroll bar, what should I use? I mean the form is large so we use scroll bar to move up and down, now I want that location to be independent of where I have set the scroll bar this.PointToClinet?
The Location property is already independent of the scrollbar position. A control at (0,0) stays at (0,0) in a panel with a scrollbar. What changes is the AutoScrollPosition property value. With a vertical scrollbar, the AutoScrollPosition.Y value becomes negative when the user scrolls down. Which makes whatever is inside the panel move up.
Trying to keep something in the same position even if the scrollbar is used is technically possible by correcting for AutoScrollPosition.Y. But doesn't work well in practice, whatever you are scrolling is doing the pogo, rapidly jumping up and down as you scroll. Which is caused by Windows blitting the scrolled pixels after which you redraw it back in the original position. Find a workaround for that problem in this post.