How to Make a Paint Program

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Make a Paint Program
Draw objects in Visual Basic.NET. (Paint brush and aqua paints image by PaulPaladin from Fotolia.com)

Knowing how to make a paint program in Microsoft Visual Basic.NET (VB.NET) can get you started using graphics in programming. VB.NET is an object-oriented programming language used to create desktop, Web and mobile applications. VB.NET offers a graphics class that can be used for drawing objects such as rectangles, circles and lines. You can use the ColorDialog control to display all available colours to the user and use the colour selected to draw your objects.

Skill level:
Moderate

Other People Are Reading

Things you need

  • Microsoft Visual Basic Express

Show MoreHide

Instructions

  1. 1

    Start Microsoft Visual Basic Express, click "New Project..." on the left pane of your screen, then select "Windows Forms Application." Click "OK."

  2. 2

    Double-click "Button" on the "Toolbox" to add a new button. Double-click "Check Box" to add a new text box. Add two more check boxes to the form. Double-click "ColorDialog" to add the control to the program. Double-click "Button1" to open the "Form1.vb"module.

  3. 3

    Copy and paste the following code inside the "Button1_Click" procedure to let the user choose a colour:

    Me.ColorDialog1.ShowDialog()

        If Me.ColorDialog1.ShowDialog = DialogResult.OK Then
    
            clr = ColorDialog1.Color
    
        End If
    
  4. 4

    Copy and paste the following under "Public Class Form1" to create two global variables used to create graphics and colour:

    Private gfx As Graphics
    
    Private clr As Color
    
  5. 5

    Click the drop arrow from the upper-left combo box and select "(Form1 Events)." Select "Load" to create the Form event and copy and paste the following inside the event:

    gfx = Me.CreateGraphics()

  6. 6

    Click the "FormClosed" event to create the event and copy and paste the following to dispose the graphics object:

    gfx.Dispose()

  7. 7

    Click the "MouseMove" event to create the event, and copy and paste the code below to draw objects when the user moves the mouse:

        If e.Button <> Windows.Forms.MouseButtons.Left Then Exit Sub
    
        Dim rect As Rectangle
    
        Dim my Pen As Pen
    
        my Pen = New Pen(clr, 2)
    
    
    
        If Me.CheckBox1.Checked Then
    
            With rect
    
                .X = e.X - 1
    
                .Y = e.Y - 1
    
                .Width = 15
    
                .Height = 15
    
            End With
    
            gfx.DrawRectangle(my Pen, rect)
    
        End If
    
    
    
        If Me.CheckBox2.Checked Then
    
            With rect
    
                .Width = 15
    
                .Height = 15
    
            End With
    
    
    
            gfx.DrawLine(my Pen, e.X, e.Y, e.X - 1, e.Y - 1)
    
        End If
    
    
    
        If Me.CheckBox3.Checked Then
    
            my Pen = New Pen(clr, 2)
    
            With rect
    
                .X = e.X - 1
    
                .Y = e.Y - 1
    
                .Width = 15
    
                .Height = 15
    
            End With
    
            gfx.DrawEllipse(my Pen, rect)
    
        End If
    
  8. 8

    Press "F5" to run your program, then click "Button1" to choose a colour for your objects. Check the first check box to draw a series of rectangles. Check the second box to draw lines or check the third check box to draw a series of circles.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.