WinForm Panel滚动而没有滚动条? [英] WinForm Panel scrolling without a scrollbar?

查看:610
本文介绍了WinForm Panel滚动而没有滚动条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个基本上是面板(内部具有随机内容)的用户控件,并且我需要能够使用按钮(上下)而不是滚动条来上下滚动该面板.

I'm creating a User Control that's basically a Panel (with random content inside), and I need to be able to scroll up and down this Panel using buttons (up and down) rather than the scrollbar.

我之所以必须这样做,是因为该程序将在触摸屏显示器上使用,并且我们需要大按钮,而不是难看的小滚动条.

The reason I have to do it this way is because the program will be used on a touch screen monitor and we need big buttons rather than an ugly little scrollbar.

我一直在搞怪VerticalScrollbar属性,它们似乎都不做任何事情.我注意到,如果将AutoScroll设置为false,则AutoScrollPosition实际上会显示坐标,但应为负值除外.另外,我注意到panel.VerticalScrollbar.Visible = true;仅当放置在构造函数之外时才似乎起作用.有什么理由吗?

I've been messing around with the VerticalScrollbar properties, and none of them seem to do anything. I've noticed that if I set AutoScroll to false, AutoScrollPosition actually shows coordinates, except negative of what it should be. Also, I've noticed that panel.VerticalScrollbar.Visible = true; only seems to work when placed outside of the constructor. Is there a reason for that?

基本上,WinForms的滚动条让我很困惑(笨拙?).有谁知道一种通过按钮以编程方式在面板上上下滚动的好方法(我不在乎是否需要一个不可见的滚动条).

Basically, WinForms' scrollbars are very confusing (buggy?) to me. Does anyone know a good way to scroll up and down a panel programmatically with buttons (I don't care if I need to have an invisible scrollbar).

谢谢! = D

推荐答案

使您的UserControl成为常规的UserControl(即从UserControl继承,而不是从Panel继承),然后将Panel放置在UserControl上.将任何内容/控件放在内部面板上,然后更改面板的Left和Top属性以在没有滚动条的情况下进行移动.您还可以在用户控件中添加按钮以处理内部面板的移动.

Make your UserControl a regular UserControl (i.e inherit from UserControl instead of Panel) and place a Panel on your UserControl. Put any content/controls on the inner Panel, and then change the Panel's Left and Top properties to move it around without scrollbars. You could also add buttons to your UserControl to handle the movement of the inner Panel.

但是,更简单的方法可能是只使用真正的宽/高滚动条,并将其Thumbwidth(我认为这是属性)设置为相同的大值-这将产生易于用手指使用的滚动条.据我所知,无法通过将Autoscroll设置为True的面板上出现的滚动条来执行此操作,因此您仍然需要使用我上面提到的方法(将内部Panel放在UserControl上)并添加滚动条自己动手.

A simpler way, however, might be to just use really wide/high scrollbars, and set their Thumbwidth (I think this is the property) to the same large value - this will produce scrollbars that are easy to use with the fingers. To my knowledge there's no way to do this with the scrollbars that appear on a Panel with Autoscroll set to True, so you'd still need to use the method I mentioned above (with an inner Panel sitting on your UserControl) and add the scrollbars to move it yourself.

我同意Windows中的滚动条很烂,因此尽管我通常只赞成使用每个人都习惯的标准控件,但在这种情况下滚动自己的文件夹并没有什么错.

I agree that scrollbars in Windows suck, so while I'm normally in favor of just using the standard controls that everyone is used to, I don't see anything wrong with rolling your own in this case.

这篇关于WinForm Panel滚动而没有滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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