希望这是一个简单的过程!
我从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;
我看到了滚动位置的新值。然而,滚动条总是返回到零。我做错了什么?
最佳答案
我无法对该代码试图执行的操作进行逆向工程。自动滚动是你的 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# - ScrollableControl 滚动条始终归零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7019877/