WinForms: How to avoid horizontal scrollbar with AutoScroll?

I am writing a custom control that contains a list of controls (child controls) that are resized horizontally to fit the width of the control. If there are many elements (or the control is changed so that it is not tall enough), then a vertical scroll bar is needed; but when a vertical scrollbar appears, the child controls suddenly become too wide, resulting in a horizontal scrollbar.

What is the right way to ensure that the horizontal scrollbar does not appear when it is not necessary, given that I control the placement of controls manually (without relying on AnchorStyles)? (Note. I cannot manage the property VScrollmanually, because I'm on the Compact Framework, and if the minimum width of the item is larger than the client area, then a horizontal scroll bar will be required.)

+3
source share
2 answers

What I did in a similar situation was after each addition of an item to the list, which I found out whether the scroll bar was visible or not, and manually adjusted the width.

What I did to determine if the scroll bar showed:

, , .

Windows, CF, , .

+2

:

System.Windows.Forms.SystemInformation.VerticalScrollBarWidth
+2

Source: https://habr.com/ru/post/1796370/


All Articles