Quantcast
Viewing latest article 2
Browse Latest Browse All 4

Drawing on mouse move/drag

Hy Shyma

Sorry to jump in here, but that previous example is quite verbose and maybe a little confusing if you are new to GDI.

Here is a very simplified example (read not production code) of how you might approach this.

If you do need to support zoming, rotating, scrolling etc then you will need to look at the Matrix class and the previous example.  I'd also recommend that you don't use lists in the final version as there is a lot of array resizing happening which you would want to avoid ... I used lists solely so that you can concentrate on the painting etc

Shout if you need any more information/help.

Richard

Public

Class PaintControl

Inherits Control

Private mAllPoints AsNew Generic.List(Of Generic.List(Of Point))

Private mCurPoints As Generic.List(Of Point)

ProtectedOverridesSub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)

mCurPoints =

New Generic.List(Of Point)

mAllPoints.Add(mCurPoints)

MyBase.OnMouseDown(e)

EndSub

ProtectedOverridesSub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)

MyBase.OnMouseMove(e)

If mCurPoints IsNotNothingThen

mCurPoints.Add(e.Location)

MyBase.Invalidate()

EndIf

EndSub

ProtectedOverridesSub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)

mCurPoints =

Nothing

MyBase.OnMouseUp(e)

EndSub

ProtectedOverridesSub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

MyBase.OnPaint(e)

ForEach lst As Generic.List(Of Point) In mAllPoints

If lst.Count > 0 Then e.Graphics.DrawCurve(Pens.Black, lst.ToArray)

Next

EndSub

End

Class

Viewing latest article 2
Browse Latest Browse All 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>