Click here to Skip to main content
15,898,035 members
Articles / Programming Languages / Visual Basic
Article

A Simple VB.NET Freehand Drawing method

Rate me:
Please Sign up or sign in to vote.
4.63/5 (30 votes)
26 Jul 2003 185.7K   4.5K   33   28
The code uses a System.Drawing.Drawing2D.GraphicsPath method to follow the users mouse movements. The path is then painted in the control.

Sample Image - Freehand_Drawing.jpg

Introduction

This is a simple freehand drawing example for VB.NET. I was frustrated at not finding a simple way to draw on a control or a picture in VB.NET. What was a simple task in VB6, seemed to take hundreds of lines of code in .NET sample code. Hopefully this will give other VB.NET programmers ideas on a simple implementation of this type of code.

The code uses a System.Drawing.Drawing2D.GraphicsPath method to follow the users mouse movements. The path is then painted in the control.

Background

Ideas for this code came from the Microsoft "Scribble" sample code, Christian Graus's excellent article on a C++ code called "Doodle" and the Microsoft website.

Note that this is a VERY pedantic freehand drawing code, so be kind in you comments. :)

History

  • Written July, 2003

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
AnswerRe: How can I save content of PictureBox Pin
ThaSaint4-Dec-08 2:56
ThaSaint4-Dec-08 2:56 
GeneralClear PictureBox1 Pin
dragondrache18-Oct-04 6:50
dragondrache18-Oct-04 6:50 
GeneralRe: Clear PictureBox1 Pin
loay454528-Apr-06 17:32
loay454528-Apr-06 17:32 
Generaldrawing color Pin
Jason Rico5-Nov-03 9:51
Jason Rico5-Nov-03 9:51 
AnswerRe: drawing color Pin
Martin Houstrup19-Apr-09 6:04
Martin Houstrup19-Apr-09 6:04 
GeneralRe: drawing color Pin
shankarBangalore27-Apr-10 1:43
shankarBangalore27-Apr-10 1:43 
GeneralRe: drawing color Pin
Martin Houstrup27-Apr-10 6:51
Martin Houstrup27-Apr-10 6:51 
BugThere is a Bug in this approach. Pin
Rockford Sol7-Jan-15 17:04
Rockford Sol7-Jan-15 17:04 
Hi,

This works fine if the color of the picturebox is going to be same.
I have a transparent picturebox, when I change background color, it change the color of form but the captured color remain the same as it is a bitmap layer. Is there any way to capture alpha or PNG rather than bitmap, so if we change back color of form, Picturebox can also show back color.
GeneralInk Object Pin
Nick Seng27-Jul-03 16:03
Nick Seng27-Jul-03 16:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.