DonnaF Posted August 11, 2003 Posted August 11, 2003 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 Quote
Leaders dynamic_sysop Posted August 11, 2003 Leaders Posted August 11, 2003 you should be using Panel.CreateGraphics() rather than just Graphics() eg: Dim graphic As Graphics = Panel1.CreateGraphics() Quote
*Experts* mutant Posted August 11, 2003 *Experts* Posted August 11, 2003 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. Quote
DonnaF Posted August 11, 2003 Author Posted August 11, 2003 Thank you for your suggestions. It works fine now! I can now write on the panel. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.