在面板上添加垂直滚动条 [英] Add vertical scroll bar to panel

查看:84
本文介绍了在面板上添加垂直滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使 Panel 滚动,但只能垂直滚动(因此 AutoScroll 无效,因为子控件必须经过左边缘并且必须经过。)

I am trying to make a Panel scrollable, but only vertically (so AutoScroll won't work because the child controls go past the left edge and must).

那么这是怎么做的?

推荐答案

假设您使用的是winforms,默认的面板组件不会为您提供禁用水平滚动组件的方法。一种解决方法是禁用自动滚动并自己添加滚动条:

Assuming you're using winforms, default panel components does not offer you a way to disable the horizontal scrolling components. A workaround of this is to disable the auto scrolling and add a scrollbar yourself:

ScrollBar vScrollBar1 = new VScrollBar();
vScrollBar1.Dock = DockStyle.Right;
vScrollBar1.Scroll += (sender, e) => { panel1.VerticalScroll.Value = vScrollBar1.Value; };
panel1.Controls.Add(vScrollBar1);

详细讨论此处

这篇关于在面板上添加垂直滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆