Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a program that is allowing a user to draw on a form, using MouseMove, MouseDown, and MouseUp events. I have added radio buttons, to allow the user to change the color and size of what they are drawing, plus a panel for the drawing area. How do I change my code from drawing on a form, to drawing on a panel? Here's my current code. Thanks, Donna

 

Public Class frmPainter

Inherits System.Windows.Forms.Form

 

 

Dim shouldPaint As Boolean = False

Dim newColor As Color = Color.Red

 

Private Sub frmPainter_MouseMove( _

ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.MouseEventArgs) _

Handles MyBase.MouseMove

 

If shouldPaint Then

Dim graphic As Graphics = CreateGraphics()

 

graphic.FillEllipse _

(New SolidBrush(newColor), e.X, e.Y, 4, 4)

End If

End Sub

 

Private Sub frmPainter_MouseDown(ByVal sender As Object, _

ByVal e As System.Windows.Forms.MouseEventArgs) _

Handles MyBase.MouseDown

 

shouldPaint = True

 

End Sub

 

Private Sub frmPainter_MouseUp(ByVal sender As Object, _

ByVal e As System.Windows.Forms.MouseEventArgs) _

Handles MyBase.MouseUp

 

shouldPaint = False

End Sub

 

End Class

  • *Experts*
Posted

You dont have to change much. Just change the event to handle the panel instead of the form:

Handles Panel1.MouseMove

And then when you create a graphics object use:

Panel1.CreateGraphics()

Instead of form's CreateGraphics method.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...