I have a form that I can draw on using the graphics circle and graphics item classes. Is thier a way that I can add in an erase function so that the user can erase something if he messes up??
Printable View
I have a form that I can draw on using the graphics circle and graphics item classes. Is thier a way that I can add in an erase function so that the user can erase something if he messes up??
here is my code that draws on the form.
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.data.sqlclient
Imports System.Data
Public Class frmdraw
Inherits System.Windows.Forms.Form
' enums....
Public Enum GraphicsTools As Integer
CirclePen = 0
End Enum
Public Enum GraphicsSizes As Integer
Small = 4
Medium = 10
Large = 20
End Enum
' members.....
Public GraphicsItem As New ArrayList
Public GraphicTool As GraphicsTools = GraphicsTools.CirclePen
Public GraphicsSize As GraphicsSizes = GraphicsSizes.Large
Public GraphicColor As Color = Color.Black
' DoMousePaint - respond to a mouse movement....
Private Sub DoMousePaint(ByVal e As MouseEventArgs)
' store the new item somewhere...
Dim newItem As GraphicsItem
' what tool are you using?
Select Case GraphicTool
' circlepen?
Case GraphicTool.CirclePen
' create a new graphics circle...
Dim circle As New GraphicsCircle
circle.SetPoint(e.X, e.Y, GraphicsSize, GraphicColor, True)
' store this for addition...
newItem = circle
End Select
' where you given an item?
If Not newItem Is Nothing Then
' add it to the list...
GraphicsItem.Add(newItem)
'invalidate...
Invalidate()
End If
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
' is the button down?
If e.Button = MouseButtons.Left Then
DoMousePaint(e)
End If
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
' is the button down?
If e.Button = MouseButtons.Left Then
DoMousePaint(e)
End If
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
' go through the list...
Dim item As GraphicsItem
For Each item In GraphicsItem
'ask each item to draw itself
item.Draw(e.Graphics)
Next
End Sub