您可以在按下鼠标按钮时设置鼠标挂钩,并在释放鼠标按钮时取消挂钩。在钩子回调中,您可以观察鼠标位置并根据需要调整控件的大小。
编辑:
您可以改为使用一个特殊的控件,用户可以拖动该控件以将滚动位置保持在父容器的右下角。用户可以拖动控件以使区域更大,如果您不使用锚点或停靠设置,您可以手动调整控件的大小以填充父区域。
不久前,我为我所做的一个项目实施了这样的事情。我把它做成三角形,看起来类似于ToolStrip
. 以下是控件中的一些代码片段ScrollHolder
:
public ScrollHolder()
{
this.Size = new Size(21, 21);
this.BackColor = SystemColors.Control;
}
protected override void OnPaint(PaintEventArgs e)
{
Point bottomLeft = new Point(0, this.Height);
Point topRight = new Point(this.Width, 0);
Pen controlDark = SystemPens.ControlDark;
Pen controlLightLight = SystemPens.ControlLightLight;
Pen controlDark2Px = new Pen(SystemColors.ControlDark, 2);
Point bottomRight = new Point(this.Width, this.Height);
e.Graphics.DrawLine(
controlLightLight,
bottomLeft.X,
bottomLeft.Y - 2,
bottomRight.X,
bottomRight.Y - 2);
e.Graphics.DrawLine(controlDark, bottomLeft, topRight);
e.Graphics.DrawLine(
controlLightLight,
bottomLeft.X + 1,
bottomLeft.Y,
topRight.X,
topRight.Y + 1);
e.Graphics.DrawLine(controlDark2Px, bottomLeft, bottomRight);
e.Graphics.DrawLine(controlDark2Px, bottomRight, topRight);
int xNumberOfGripDots = this.Width / 4;
for (int x = 1; x < xNumberOfGripDots; x++)
{
for (int y = 1; y < 5 - x; y++)
{
DrawGripDot(e.Graphics, new Point(
this.Width - (y * 4), this.Height - (x * 4) - 1));
}
}
}
private static void DrawGripDot(Graphics g, Point location)
{
g.FillRectangle(
SystemBrushes.ControlLightLight, location.X + 1, location.Y + 1, 2, 2);
g.FillRectangle(SystemBrushes.ControlDark, location.X, location.Y, 2, 2);
}
protected override void OnResize(EventArgs e)
{
this.SetRegion();
base.OnResize(e);
}
private void SetRegion()
{
GraphicsPath path = new GraphicsPath();
path.AddPolygon(new Point[]
{
new Point(this.Width, 0),
new Point(this.Width, this.Height),
new Point(0, this.Height)
});
this.Region = new Region(path);
}
就实际行为实现而言,您可能希望:
- 当滚动条移出可见区域时滚动到滚动条:
Thread.Sleep
滚动到滚动架时,通过调用一小段时间(例如 50 毫秒)来减慢它的速度。