无需 AutoScroll 即可获得实时滚动 [英] Get real-time scrolling without AutoScroll

查看:27
本文介绍了无需 AutoScroll 即可获得实时滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

询问后:当包含的控件获得焦点时阻止自动滚动我找到了一种没有 AutoScroll 的滚动条的方法(使用可以访问 VScroll 属性的派生类).但是 - 它不是实时的.即只有当用户完成滚动时,控件才会真正滚动.(与带有 AutoScroll = true 的面板相反.)那么我如何让它实时滚动?

After asking this: Prevent AutoScroll when contained Control gets focus I've found a way to have a scrollbar without the AutoScroll (using a derived class which can access the VScroll property). However - it's not in real-time. i.e. Only when the user is done scrolling does the Control actually get scrolled. (as opposed to a Panel with AutoScroll = true.) So how do I get it to scroll in real-time?

我的代码:

using System.Drawing;
using System.Windows.Forms;

namespace test
{
    public partial class Form1 : Form
    {
        MyPanel panel = new MyPanel
        {
            //AutoScroll = true,
            Size = new Size(200, 200),
            Location = new Point(0, 30),
            BackColor = Color.Green
        };
        Button b1 = new Button
        {
            Location = new Point(100, 100),
            Size = new Size(50, 150),
            BackColor = Color.Black
        };
        Button b2 = new Button();

        public Form1()
        {
            InitializeComponent();
            panel.Controls.Add(b1);
            Controls.Add(panel);
            Controls.Add(b2);
            Shown += new System.EventHandler(Form1_Shown);
        }

        void Form1_Shown(object sender, System.EventArgs e)
        {
            panel.VerticalScroll.Visible = true;
            panel.SetV();
        }
    }

    class MyPanel : Panel
    {
        public void SetV() { VScroll = true; }
    }
}

推荐答案

如评论所示:

您需要覆盖面板的 OnScroll() 方法并调用SetDisplayRectLocation(0, -se.NewValue).

You'll need to override the panel's OnScroll() method and call SetDisplayRectLocation(0, -se.NewValue).

这就是这个问题的答案.

That's the answer to this question.

但是,我发现我不能同时拥有两个滚动条.或者至少 - 我还没有找到办法做到这一点.

However, I've found that I can't have both scrollbars simultaneously. Or at least - I haven't found a way to do it.

这篇关于无需 AutoScroll 即可获得实时滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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