ScrollableControl 滚动条总是归零 [英] ScrollableControl scroll bars always return to zero

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

问题描述

希望这是一个简单的!

我是从 UserControl 派生的,我正在覆盖 OnPaint.我希望这个控件是可滚动的,但我想要的只是能够获取滚动条的值并自己处理在哪里绘制所有内容.我已经设置了以下内容:

I'm deriving from UserControl, and I am overriding OnPaint. I want this control to be scrollable, but all I want is to be able to get the value of the scroll bars and handle where to draw everything myself. I have set up the following:

// How the hell do I get this scrolling to not return to zero?
this.Scroll += new ScrollEventHandler(TimelineControl_Scroll);

this.HorizontalScroll.Enabled = true;
this.HorizontalScroll.Visible = true;
this.HorizontalScroll.Minimum = 0;

this.VerticalScroll.Enabled = false;
this.VerticalScroll.Visible = true;

this.AutoScroll = false;

我看到了滚动位置的新值.但是,滚动条总是归零.我做错了什么?

I am seeing the new value of the scroll position. However, the scroll bars always return to zero. What am I doing wrong?

推荐答案

我无法对该代码尝试执行的操作进行逆向工程.AutoScroll 是您的朋友.举个例子:

I cannot reverse-engineer what that code is trying to do. AutoScroll is your friend. Here's an example:

public partial class UserControl1 : UserControl {
    public UserControl1() {
        InitializeComponent();
        this.SetStyle(ControlStyles.ResizeRedraw, true);
        this.AutoScroll = true;
        this.AutoScrollMinSize = new Size(1000, 0);
    }
    protected override void OnScroll(ScrollEventArgs se) {
        base.OnScroll(se);
        this.Invalidate();
    }
    protected override void OnPaint(PaintEventArgs e) {
        e.Graphics.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);
        e.Graphics.DrawLine(Pens.Black, 0, 0, 1000, this.ClientSize.Height);
        base.OnPaint(e);
    }
}

这篇关于ScrollableControl 滚动条总是归零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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