gpt4 book ai didi

c# - Scrollable Control 滚动条总是归零

转载 作者:行者123 更新时间:2023-11-30 22:36:26 29 4
gpt4 key购买 nike

希望这是一个简单的过程!

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

// 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;

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

最佳答案

我无法对代码试图做什么进行逆向工程。 AutoScroll 是您的 friend 。这是一个例子:

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);
}
}

关于c# - Scrollable Control 滚动条总是归零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7019877/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com