C# Panel autoscroll doesn't work

匿名 (未验证) 提交于 2019-12-03 02:06:01

问题:

I have a panel with a picturebox on it. When the content of the picturebox is too large I want scrollbars. I've set the autoscroll set to true on the panel. But when the content of the picturebox is larger then the height of the panel/picturebox no scrollbars are shown.

My panel is anchored top, left, bottom, right. The picturebox is also anchored top, left, bottom, right.

回答1:

You'll have to set the SizeMode property to AutoSize which causes the PictureBox to automatically resize to the picture's size.



回答2:

From MSDN:

There is currently a limitation in Windows Forms that prevents all classes derived from ScrollableControl from acting properly when both RightToLeft is enabled and AutoScroll is set to True. For example, let's say that you place a control such as Panel― or a container class derived from Panel (such as FlowLayoutPanel or TableLayoutPanel) ― on your form. If you set AutoScroll on the container to True and then set the Anchor property on one or more of the controls inside of the container to Right, then no scrollbar ever appears. The class derived from ScrollableControl acts as if AutoScroll were set to False.



回答3:

The picturebox should not be anchored bottom and right. Instead, resize it to the content to display.



回答4:

For me below code helped in adding scrollbar:

Panel2.Controls.Clear(); Panel2.AutoScroll = false; Panel2.VerticalScroll.Enabled = true; Panel2.VerticalScroll.Visible = true;  Panel2.AutoScroll = true; 


回答5:

Change the Panel's Border Style to Fixed Single and then the Panel's Auto Scroll Property to True.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!