Click to See Complete Forum and Search --> : Quick question - lines
alex_read
Nov 28th, 2001, 10:59 AM
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 SubWhy will that work, but if I change it to this it doesn't print anything ?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
Hack
Nov 28th, 2001, 12:17 PM
Here is something that is interesting. This worksPrivate Sub Command1_Click()
'from a command button click event
Me.AutoRedraw = True
LineTo Picture1.hdc, 200, 200
End SubHowever, this does notPrivate Sub Form_Load()
'from Form_Load event
Me.AutoRedraw = True
LineTo Picture1.hdc, 200, 200
End SubI'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.
darrenl
Nov 28th, 2001, 12:29 PM
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.
Private Sub Form_Load()
Me.AutoRedraw = True
LineTo picture1.hdc, 200, 200
End Sub
Frans C
Nov 28th, 2001, 12:53 PM
Yes, it al has to do with AutoRedraw.
You have two possibilities:
Set AutoRedraw on for the picturebox:
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.
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:
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
alex_read
Nov 29th, 2001, 02:22 AM
Wow, thanks guys, didn't know there was an autoredrawproperty for anything apart from the form :rolleyes:
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.