110,043
社区成员




public partial class Form1 : Form
{
private int lineX=10;
private int lastX = -1;
public Form1()
{
InitializeComponent();
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawLine(SystemPens.ControlText, new Point(lineX, 0), new Point(lineX, this.Height));
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (Math.Abs(e.X - lineX) < 5)
{
lastX = e.X;
}
else
{
lastX = -1;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (this.Capture && lastX!=-1)
{
lineX += e.X - lastX;
lastX = e.X;
this.Invalidate();
return;
}
if (Math.Abs(e.X - lineX) < 5)
{
this.Cursor = Cursors.SizeAll;
}
else
{
this.Cursor = Cursors.Default;
}
}
}