There is no such thing. The line is not an object of a type implementing events. Moreover, the line is not an object at all.
All you can do is adding an event handler to the control used to draw your line on. Alternatively, you can override mouse-handling virtual methods. How this event is related to the line — is all your business. You can define some criteria used to find out of a mouse is "close" to some point of a line at the moment of pressing a mouse key down. The schema is this:
class MyContol : System.Windows.Forms.Control {
public MyContol() {
ThePen = new System.Drawing.Pen();
SetStyle(System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer);
SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint)
}
protected override void Dispose(bool disposing) {
if (disposing)
ThePen.Dispose();
}
protected override void OnPaint(PaintEventArgs e) {
System.Drawing Point p1 =
System.Drawing Point p2 =
e.Graphics.DrawLine(ThePen, p1, p2);
}
protected override void OnMouseDown(MouseEventArgs e) {
base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e) {
base.OnMouseUp(e);
}
protected override void OnMouseMove(MouseEventArgs e) {
base.OnMouseMove(e);
if ()
Invalidate();
}
System.Drawing.Pen ThePen;
}
The key is your data model here: you need to represent all you draw in some pure-data model and keep in the memory of you class. Update of the model by mouse, keyboard, controls, etc. needs
Invalidate
to be called. You can use
Invalidate
with a parameter (
Rectangle
or
Region
) to redraw only a part of the scene.
A bonus advice: implement your rendering method as a separate method of the same class, make a parameter of the type
Graphics
. In this way, you can call it no only from
OnPaint
, but from somewhere else using different instance of the
Graphics
: of a bitmap for exporting the graphics to a bitmap, of a printer document to print it, etc.
—SA