Public Class Form1
    Dim pero As New Pen(Color.Red, 3)
    Dim bmp As Bitmap
    Dim g As Graphics, grap As Graphics
    Dim x As Long, y As Long
    Dim openfile As New OpenFileDialog
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PictureBox1.Cursor = Cursors.Cross
        openfile.Filter = "Image Png|*.png|Image Jpg|*.jpg"
        If openfile.ShowDialog = DialogResult.Cancel Then Exit Sub
        PictureBox1.Image = Image.FromFile(openfile.FileName) : Me.Text = ("Paint : " & openfile.SafeFileName)
        bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height)
        g = Graphics.FromImage(bmp)
        grap = PictureBox1.CreateGraphics
        'Гладкая линия
        pero.StartCap = Drawing2D.LineCap.Round
        pero.EndCap = Drawing2D.LineCap.Round
        'Рисуем заданое изображение
        g.DrawImage(New Bitmap(openfile.FileName), 0, 0)
        grap.DrawImage(New Bitmap(openfile.FileName), 0, 0)
        PictureBox1.Image = bmp
    End Sub
    Dim savefile As New SaveFileDialog
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        savefile.Filter = "Image Png|*.png|Image Jpg|*.jpg"
        If savefile.ShowDialog = DialogResult.Cancel Then Exit Sub
        bmp.Save(savefile.FileName)
    End Sub
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        'Запоминаем координаты 
        x = e.X
        y = e.Y
    End Sub
    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If MouseButtons = MouseButtons.Left Then
            g.DrawLine(pero, e.X, e.Y, x, y)
            grap.DrawLine(pero, e.X, e.Y, x, y)
            PictureBox1.Image = bmp
            x = e.X
            y = e.Y
        End If
    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        pero.Width = TrackBar1.Value
    End Sub
    Dim col As New ColorDialog
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If col.ShowDialog = DialogResult.Cancel Then Exit Sub
        pero.Color = col.Color
    End Sub
End Class
