I am having difficulty getting both the vertical and horizontal scroll bars to behave as desired in my situation. The page in question has multiple sections that can be expanded and collapsed (only one can be expanded at a time). To try and demonstrate the layout of my page I'm going to use nesting and perhaps a silly naming convention to be as clear as possible:
ucParent
pnlParent
pnl1Title
pnl1
uc1
pnl2Title
pnl2
uc2
pnl3Title
pnl3
uc3-1
uc3-2
uc3-3
And so on. Now, pnlParent has dock=fill, while the child panels are dock=top. All the pnlXTitle panels have buttons that trigger the expanding/collapsing behavior by setting their respective panels directly underneath to enabled=visible=false.
I'm wanting the horizontal and vertical scroll bars to show up as needed when the window is resized and hiding content, however I am not being successful at eliciting this behavior.
With ucParent.AutoScroll=false and pnlParent.AutoScroll=true only the vertical scroll bar is present.
With ucParent.AutoScroll=true and pnlParent.AutoScroll=false neither scrollbar works.
With both ucParent.AutoScroll=true and pnlParent.AutoScroll=true only the vertical scroll bar is present.
In all the above examples, AutoScroll=false for all the other panels and user controls. From what I've read so far, I fear the dock=top setting may be interfering with the horizontal scroll bar behavior. I can force it to display and work by using AutoScrollMinSize, but the panels are of different sizes making this feel like much more of a hack than a proper solution.
Through my searching I found a good number of previous discussions revolving around Windows Forms and scrollbars, but I didn't find anything specific enough I feel I can confidently determine the necessary direction for my application. I would very much appreciate any information you could share that would shed light on why the scroll bars are not working as desired and how that can be remedied.
Thank you!
The problem you're experiencing has to do with the way that docking resizes your controls to fit horizontally within the form.
When you dock a control to the top of its container, it is stretched to fit within the container. Consequently, no part of it falls outside of the container, and there is no need to display the horizontal scroll bar. This is why your scroll bar isn't appearing.
This behavior is by design.
Related
I asked this over at StackOverflow and someone suggested I try here, so...This program uses winforms and c# (no wpf). I have a panel with buttons on it and getting it to scroll is no problem. However, when the program is on a hi-resolution touch screen -- like a Surface 7 -- trying to touch in the exact right spot to get it to scroll is hit and miss. I've searched and have yet to find a way to make the grab area (so to speak) of a vertical scroll bar wider so that when you touch the screen, the control actually picks up the event. Any ideas on how to do this?
This can be a super user question if youre looking for a tool to make it wider for all apps because it could be considered as an accessibility.
If you're writing an app
Vertical Scroll Bar Width
System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;
Horizontal Scroll Bar Width
System.Windows.Forms.SystemInformation.HorizontalScrollBarHeight;
Duplicate of
Change width of scrollbars
I've tried looking many places for an answer to an issue I'm having and so far I've found nothing.
What I currently have is a c# windows form with user controls inside it. Some user controls have other controls inside them. What happens when I change the text in a textbox, is its parent windows will no longer resize like they should when changing the window size. i.e. A horizontal scrollbar will appear even though horizontal scrollbars are disabled in that specific window. Its almost as if changing the text changes the parent window's styling.
In case this is too vague, I have a textbox inside a panel with a docking property set to fill. The panel has a padding of 10 in order to allow the textbox to have some white space for aesthetic purposes. This control resides within a parent control (we'll call it parent 1), which in turn resides within another control as well (we'll call it parent 2). So when I change the textbox's text (at all, even adding a space), will then make parent 2 have a horizontal scrollbar flicker and sometimes even remain when resizing the form window manually.
You should make sure that not only the TextBox in the UserControl is docked to fill but also that the user control itself and its parent (and its parent) are Docked correctly or have anchor set so that they resize with the Form.
Do you execute any special code when the user enters a character? (KeyPressed event etc.). If yes you should try disabling the events temporarily to see if they cause the problem.
If you post a sample of your code it would be easier to help. Without this we can only guess, like I tried...
I found out my issue! When using autoScrollBars and double buffering, it caused the horizontal scrollbar to show when it shouldn't have (at least in my case) when resizing the window. The answer was simple, forget the autoScrollBars, and implement my own vertical scroll bar!
I was actually getting some code to post up on here for you guys to look at, but when looking at it, I decided to forget the autoscroll, and lo and behold it worked!
I'm actually curious as to why that is though. My friend heard that .net has some issues with autoScroll but I didn't think it would be to this degree.
Kinda new in Microsoft visual C#. I have made a simple program. Everything is working perfectly fine, unfortunately the tricky part for me is i do not know how to layout my objects properly. I would like to copy the layout of the Microsoft visual C# interface, wherein the panels adjust to their predefined ratio and proportion whenever the main form is re-sized and the user may adjust the width and height of each panel. Any readings or code would be a lot of Help. THANKS A LOT!
You could do a number of things:
Allow automatic layout using something like a FlowLayoutPanel
Allow resizing of controls using a Splitter
Look at custom implementations to provide more advanced functionality Collapsible Splitter
Well follow these tutorial links to know about resizing in windows
using Dock and Anchor property. Along this the layout control will
help you to manage the layout - FlowLayoutPanel and
TableLayoutPanel, Panel, GroupBox etc.
Designing Resizable Windows Forms in Visual Studio .NET
Manage WinForm controls using the Anchor and Dock properties
This one is much better to understand.
For a simple start the anchor property is what you want. so for instance if you set all four anchors for that left hand control, and the parent window changes size it will will resize proportionally.
After that it starts getting complicated. Adding panels and then putting your controls inside them. Setting Dock to left, or top or fill. Grow and shink on scrollable controls. Splitter bars.
And last ditch handling resize events and calculating positions and sizes.
Sit down and have a think about what you want to happen, play around with minimum and maximum height and widths, ie no point in working out waht your form is going to look like when it's postage stamp sized...
PS Don't forget VS allows floating panels, and persists (well some times sort of) user choices in the layout, that's a bigger job.
Place a TableLayoutPanel as the base control, anchor it to all sides, define as many columns and rows as you like with "percentage" sizes.
Then place different sections of your form in different table cells. Properly dock your controls in each cell.
Can also use a split container above table if needed.
The ideal order should be like below
SplitContainer
TableLayoutPanel
Panel
Controls
I have simple WinForms GUI that I want to use with TabPages. The problem I'm having is resizing and working with multiple sizes of screens. What settings do I change for each TextBox, GroupBox to make it fit the screen nicely without making it feel to the user like it's badly designed?
Usually I would use Dock Fill but it doesn't work with more then 1 GroupBox. Then I checked/played with Anchor trying to make it bind to Top, Left, Right, Bottom for everything but that makes a big mess (textboxes overlapping other label, texboxes etc.). I tried to choose some here, some here but whenever I try resize unexpected things happen. How would I go from here? My system is 24" and resolution 1920x1080p, but my users often have a range from 1024x768 to 1920x1080.
Right now I'm using Devexpress controls but the question applies to both Devexpress and builtin controls.
First, set the form size in the designer to a bit less than the minimum expected resolution - say 900x650 or so. Then you can design a form that will work at all resolutions even if it doesn't get resized.
Next, work out which controls should stay a fixed size, and which should stretch/grow as the form us made bigger. Firstly, some fields won't benefit from being enlarged (e.g if you have a text box that always contains a percentage of up to 3 digits, it is pointless or even counter-productive to allow it to grow big enough to show 9 digits. Secondly, some fields fill the entire width of the form, so they naturally will work better if they grow with it.
Now, set the anchoring. In general, anchor the edge of a control to the nearest edge of the form. If you set only one anchor, the control will not stretch, and the anchored edge will start the same distance from that side of the form.
If you want a control to stretch, anchor opposing sides (eg left and right). This will keep those edges the same distance from the form's edges, so the control will stretch to fit.
You will see that if one control is anchored in place, and the control next to it is set to stretch, there is a good chance that they'll end up overlapping, so you must treat all controls across the form as a related group.
For more control, place groups of controls into a container control like a panel or group box. Then their anchoring relates to their parent group, and the group can be anchored to the form.
To see the effects, just resize the form in the designer and see where everything goes - then undo and fix any anchoring that didn't work. You'll soon get a feel for how the layout works, and how to design forms to work well with resizing.
A disclaimer first! This might be a very fundamental question, but I have started learning Winforms Application Development on my own (.net 3.5,C#), and I have this resizing question.
I am developing a small Winforms application that has a standard tab control (along with many other controls) placed in the form. (It has 5 TabPages)
The AutoScroll property for the TabPage has been set to “True”. On reading up what I got to understand is that this will enable the scrollbars to show up at run time while resizing. i.e if the height of the form is reduced it will cause the vertical scrollbar to show up within the TabPage.
While the application is running, what I noticed is that if I reduce the height of the form using the little double headed arrow, the scroll bar does not stay on top, i.e if I adjust the height from below, the bottom end of the scrollbar is no longer there. More precisely I am just looking for a way to keep both ends of the scrollbar on top within a TabPage when the form containing the Tab control is resized.
It sounds like the problem is that the tabbed control will show scrollbars and may well autosize, but you haven't told the form what to do.
You might want to look at the 'Dock' property of controls, which causes a control to fill a specific area of the form (or other parent control), no matter what it is resized to.