Results 1 to 5 of 5

Thread: Quick question - lines

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Quick question - lines

    Code:
    Private Declare Function LineTo Lib "gdi32" _
    (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    
    Private Sub Form_Load()
        Me.AutoRedraw = True
        LineTo Me.hdc, 200, 200
    End Sub
    Why will that work, but if I change it to this it doesn't print anything ?
    Code:
    Private Declare Function LineTo Lib "gdi32" _
    (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    
    Private Sub Form_Load()
        Me.AutoRedraw = True
        LineTo picture1.hdc, 200, 200
    End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Here is something that is interesting. This works
    VB Code:
    1. Private Sub Command1_Click()
    2. 'from a command button click event
    3. Me.AutoRedraw = True
    4. LineTo Picture1.hdc, 200, 200
    5. End Sub
    However, this does not
    VB Code:
    1. Private Sub Form_Load()
    2. 'from Form_Load event
    3. Me.AutoRedraw = True
    4. LineTo Picture1.hdc, 200, 200
    5. End Sub
    I'm not sure why, but then I've very little experience (read that as 0 (zero)) with using the LineTo API. Perhaps some graphics folks out there knows why it works in a click event, but not in a form load event.

  3. #3
    Addicted Member darrenl's Avatar
    Join Date
    Jul 2000
    Location
    Portsmouth, UK
    Posts
    148
    It's all to do with the autoredraw propery. In the not working example you where setting the form object (me.) to autoredraw = true. To get the picture example working you need to use set the picture object to autoredraw = true.

    Code:
    Private Sub Form_Load()
        Me.AutoRedraw = True
        LineTo picture1.hdc, 200, 200
    End Sub
    Dazzer

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Yes, it al has to do with AutoRedraw.
    You have two possibilities:

    Set AutoRedraw on for the picturebox:
    Code:
    Private Sub Form_Load()
        Picture1.AutoRedraw = True
        LineTo Picture1.hdc, 200, 200
    End Sub
    Or leave AutoRedrw off, but use the paint Event. Note that you have to set the starting point back to zero.
    Code:
    Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Long) As Long
    Private Sub Picture1_Paint()
        MoveToEx Picture1.hdc, 0, 0, 0
        LineTo Picture1.hdc, 200, 200
    End Sub
    Note that I modified the definition of the MoveToEx function, because I didn't want to use the original position.
    The actual declaration is:
    Code:
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    
    Private Declare Function MoveToEx Lib "gdi32" Alias "MoveToEx" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long

  5. #5

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Wow, thanks guys, didn't know there was an autoredrawproperty for anything apart from the form

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

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