给你个用ControlPaint画线的例子看看? protected override void OnMouseDown(MouseEventArgs e) { // Check if the left mouse button has generated the associated event. if(e.Button == MouseButtons.Left) { // Store the starting point for your rubber-band line. ptsStart.X = e.X; ptsStart.Y = e.Y; // Store the previous end point for your rubber-band line. ptsPrevious = ptsStart; } base.OnMouseDown (e); } protected override void OnMouseMove(MouseEventArgs e) { // Check if the left mouse button is pressed. if( e.Button == MouseButtons.Left) { // Declare a local variable for the current //end point of your rubber-band line. System.Drawing.Point ptsCurrent = new Point(); // Store the current end point of your rubber-band line. ptsCurrent.X = e.X; ptsCurrent.Y = e.Y; // Draw your actual rubber-band lines. ControlPaint.DrawReversibleLine(PointToScreen(ptsStart), PointToScreen(ptsPrevious), Color.Black); ControlPaint.DrawReversibleLine(PointToScreen(ptsStart), PointToScreen(ptsCurrent), Color.Black); // Store the current end point for the next call to OnMouseMove. ptsPrevious = ptsCurrent; } base.OnMouseMove (e); }
protected override void OnMouseDown(MouseEventArgs e) {
// Check if the left mouse button has generated the associated event.
if(e.Button == MouseButtons.Left) {
// Store the starting point for your rubber-band line.
ptsStart.X = e.X;
ptsStart.Y = e.Y;
// Store the previous end point for your rubber-band line.
ptsPrevious = ptsStart;
} base.OnMouseDown (e);
} protected override void OnMouseMove(MouseEventArgs e) {
// Check if the left mouse button is pressed.
if( e.Button == MouseButtons.Left) {
// Declare a local variable for the current
//end point of your rubber-band line.
System.Drawing.Point ptsCurrent = new Point();
// Store the current end point of your rubber-band line.
ptsCurrent.X = e.X;
ptsCurrent.Y = e.Y;
// Draw your actual rubber-band lines.
ControlPaint.DrawReversibleLine(PointToScreen(ptsStart),
PointToScreen(ptsPrevious), Color.Black);
ControlPaint.DrawReversibleLine(PointToScreen(ptsStart),
PointToScreen(ptsCurrent), Color.Black);
// Store the current end point for the next call to OnMouseMove.
ptsPrevious = ptsCurrent;
} base.OnMouseMove (e);
}