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

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

问题描述

我正在尝试使 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).

这是怎么做到的?

推荐答案

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

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天全站免登陆