VB.NET Tutorial For Beginners – Drawing To A Form And Saving Your Image (Visual Basic .NET)

In this Visual Basic .NET tutorial I’ll teach to how to create a simple drawing application and save your picture to an image file.

We’ll be using a PictureBox control as our drawing surface, and we’ll use a ColorDialog to change our paintbrush color, as well as a ComboBox to select our brush size.

TUTORIAL FEATURES:
Mouse Events – Capturing Mouse Coordinates, Clicks, and Drawing
Subs – Creating a paint brush
Form Controls – PictureBox, ComboBox, ColorDialog, Button
Bitmap – Create and Copy Images, Saving to file

:-)

Comments

Arthchie Almirante says:

is there a way that can add a undo button…

Nagisa Furukawa says:

What about if I have a list view displaying images and i want to save them in a created directory, how can I do so?

polas anderson says:

I suggest for you 😉
What about if you create tut about how to open from openfiledialog picture draw to picture and save it on desktop example ?

Ivan James Legaspi says:

It just draws a bunch of dots if the mouse moves too fast. Please help.

The Revenge 1- says:

plz help picturebox saves in white image whitout the drawing

Anis Ahmadi says:

hello
thank you for this video
I’m asking if you can upload the source code plz

dukesTT says:

There are no mistakes, just happy little accidents….

First Name Last Name says:

Also, i want to draw to an image, and it wont let me, a custom image i can select with a opendialog and it wont draw to it, could you help me?

buddyroach says:

what if i want to save it as gif? i tried and it made the image all weird looking and bad quality but it was a gif from the start and looked better. how do i get full quality rendering on gifs?

colorpaper princess says:

wow cool!!!

First Name Last Name says:

For your second idea on the thing without rectangles, my program crashes when trying to use this

dim thickness as integer = “1”
dim thickness1 as string = thickness.ToString + “.0F”
or this dim thickness1 as string = thickness + “.0F”

mousemove:

qMouse.Enqueue(e.Location)
PaintBrush(thickness)

Carlos Alberto Araujo says:

Very impressive…
WHAT IF… we could build our own Photo viewer, using that method (having a Table to store the paths from photos and retrieve the paths for the Form) ?
That would be… really FUN !
Thank you for your shared amazing abilities.

Rucksack Gamer says:

A little bit of editing of the code I created a proper save dialog…

Terry K says:

I discovered VBToolbox earlier this week and have gone through a dozen of your Tutorials. I find them excellent. The pace is perfect and you explain things clearly. Thank you so much for taking the time to put these together and share them with us!

David Contreras says:

Thank you very much. This video helped me a lot. A very didactic example. Good job

Math Teacher says:

You rock man!
I really appreciate this example!

Redon Alla says:

Hi Vbtoolbox! I have seen your tutorials and I love them. I am working in a program and in my program I have 3 PictureBox and 1 TextBox and I wont to blend 2 pictures and the text on TextBox in the third PictureBox and save that picture. Can You help me PLEASE.

Math Teacher says:

Thank You.

Paritosh Shah says:

thanx a lot. working gr8

Mohammed Zerzouri says:

I love your tutorials man :) great job and thank you so much
I was wondering if you can make a tutorial and show us how to create an e-signature for a vb application !
I did create 1 following this tutorial but the signature is kinda different and I would like to save it to a db …
 I found a tool called inksecuresignature but I didn’t know how to use to save the signature into db or png …
can yo u help plz ?
thanks

RMC SISTEMAS NET says:

Imports System.Drawing

Public Class Form1
Dim Draw As Boolean
Dim DrawColor As Color = Color.Black
Dim DrawSize As Integer = 6

Dim bmp As Bitmap
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cbxSize.SelectedIndex = 2

bmp = New Bitmap(pbDraw.Width, pbDraw.Height)
pbDraw.Image = bmp

End Sub

Private Sub PaintBrush(ByVal x As Integer, ByVal y As Integer)
Using g As Graphics = Graphics.FromImage(pbDraw.Image)
g.FillRectangle(New SolidBrush(DrawColor), New Rectangle(x, y, DrawSize, DrawSize))

End Using

pbDraw.Refresh()

End Sub

Private Sub pbDraw_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pbDraw.MouseDown

Draw = True

PaintBrush(e.X, e.Y)

End Sub

Private Sub pbDraw_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pbDraw.MouseMove
If Draw = True Then
PaintBrush(e.X, e.Y)
End If
End Sub

Private Sub pbDraw_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pbDraw.MouseUp
Draw = False
End Sub

Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click
bmp = New Bitmap(pbDraw.Width, pbDraw.Height)
pbDraw.Image = bmp
End Sub

Private Sub cbxSize_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxSize.SelectedIndexChanged
DrawSize = cbxSize.SelectedItem
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
DrawColor = ColorDialog1.Color

End If
End Sub

Private Sub cmdSalve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSalve.Click

‘ SaveFileDialog1.ShowDialog()
‘ pbDraw.DrawToBitmap(bmp, New Rectangle(0, 0, pbDraw.Width, pbDraw.Height))
‘ bmp.Save(“Test1.png”, Imaging.ImageFormat.Png)
‘ bmp = New Bitmap(pbDraw.Width, pbDraw.Height)

SaveFileDialog1.ShowDialog()

If SaveFileDialog1.FileName > “” Then

pbDraw.Image.Save(SaveFileDialog1.FileName)

End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
ColorDialog2.ShowDialog()
pbDraw.BackColor = ColorDialog2.Color
End If

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
OpenFileDialog1.Filter = “image file (*.jpg, *.bmp,*.png)|*.jpg;*.bmp;*.png|all files(*.*)|*.*”
If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
pbDraw.Image = Image.FromFile(OpenFileDialog1.FileName)

End If

End Sub
End Class

robi ayna says:

it was a wonderfull tutorial;….thanks so much
can you help me how to draw lines (any graphics) during run time and make some selection using mouse to assign values……
thanks so much

First Name Last Name says:

Could you make a tutorial on adding text do it also? or if you could, add the code to do so… not the whole program, just the snippit

Bruce Lim Xiao Long says:

Hi, I have a form with animation morphing. I wanted to save it into a .gif file with that animation. Is it possible?

buddyroach says:

when i draw, it skips across the canvas into little dots. how do you make it continue to draw in a continuous stoke?

cahyo anggoro seto says:

i love you alll :* :* :* :*

cedie catahumber says:

very helpful on my thesis. wheres the other tutorial to how  save the picture in document and i can use different file name??

Titichaya Pattamawat says:

Hi, thank you for your video .
I have some question about How do I control name of image with textbox ,date and time?

new leaf88 says:

Thanks for another great Tutorial! I look forward to all your tutorials because you are clear and concise. Thank you so much VB Toolbox. Hopefully you might do videos on macros/bots webbrower/webrequest :)

Write a comment

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours