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
🙂
Amazon Auto Links: No products found.
is there a way that can add a undo button…
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?
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 ?
It just draws a bunch of dots if the mouse moves too fast. Please help.
plz help picturebox saves in white image whitout the drawing
hello
thank you for this video
I’m asking if you can upload the source code plz
There are no mistakes, just happy little accidents….
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?
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?
wow cool!!!
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)
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.
A little bit of editing of the code I created a proper save dialog…
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!
Thank you very much. This video helped me a lot. A very didactic example. Good job
You rock man!
I really appreciate this example!
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.
Thank You.
thanx a lot. working gr8
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
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
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
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
Hi, I have a form with animation morphing. I wanted to save it into a .gif file with that animation. Is it possible?
when i draw, it skips across the canvas into little dots. how do you make it continue to draw in a continuous stoke?
i love you alll :* :* :* :*
very helpful on my thesis. wheres the other tutorial to how save the picture in document and i can use different file name??
Hi, thank you for your video .
I have some question about How do I control name of image with textbox ,date and time?
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 🙂