Results 1 to 10 of 10

Thread: Drawing program

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Posts
    2

    Question Drawing program

    Ok. So you've all seen MS paint, the default drawing program that comes with windows 95+, with the line commandbutton (a basic thing common to most drawing programs I would hope). How would I duplicate that commandbutton in VB5?

    Also, does the code from VB4and 3 work the same as the code for VB5?

    (Btw, I'm a beginner)


  2. #2
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    hmmmmm

    do you mean the draw function?
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  3. #3
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    heres a drawing function

    insert a PictureBox on your form
    then paste this code in the app:


    Dim DrawNow As Boolean

    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    DrawNow = True
    Picture1.Line (X, Y)-(X, Y)
    End Sub

    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If DrawNow = True Then
    Picture1.Line -(X, Y), vbRed
    End If
    End Sub

    Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    DrawNow = False
    End Sub
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  4. #4
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Use the Line function! Here's some code:

    VB Code:
    1. Dim X1 As Long, Y1 As Long
    2.  
    3. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    4.     X1 = X
    5.     Y1 = Y
    6. End Sub
    7.  
    8. Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    9.     Picture1.Line (X1, Y1)-(X, Y)
    10. End Sub

    Click and drag on the picturebox, it'll draw a line
    You can also set some properties in the picturebox so it paints in another color, or with another line size
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Posts
    2
    No I mean the Line function which draws only straight lines. When the left mousebutton is clicked and held, then dragged to a new location, there is a straight line from where the mouse clicked to where the mouse is after it's moved.

  6. #6
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    ok......

    use 2 pictureboxes
    set picture1 and picture2's autoredraw to true
    set picture2's visible to false

    insert code:

    Dim X1 As Long, Y1 As Long
    Dim DrawNow As Boolean

    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    DrawNow = True
    X1 = X
    Y1 = Y
    End Sub

    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If DrawNow = True Then
    Picture1.Cls
    Picture1.Line (X1, Y1)-(X, Y)
    End If
    End Sub

    Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    DrawNow = False
    Picture2.Picture = Picture1.Image
    Picture1.Picture = Picture2.Picture
    End Sub
    Last edited by cyborg; Sep 20th, 2001 at 08:58 AM.
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  7. #7
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Yeah, but that has a small problem... you'll erase all the other lines whenever you create a new one...
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  8. #8
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    nope! not if you set autoredraw to true on both pictureboxes
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  9. #9
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    im working on a paint program....
    check it out if you want to...
    i've just made som big changes so its still buggy if you have more
    than one picture open

    if you want the source just tell me
    Attached Files Attached Files
    Last edited by cyborg; Sep 20th, 2001 at 09:00 AM.
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  10. #10
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Heh, don't worry, it will get better with time

    Still it's not that bad for a paiting program made in vb
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width