|
-
Nov 28th, 2001, 11:59 AM
#1
Thread Starter
Evil Genius
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
-
Nov 28th, 2001, 01:17 PM
#2
Here is something that is interesting. This works
VB Code:
Private Sub Command1_Click()
'from a command button click event
Me.AutoRedraw = True
LineTo Picture1.hdc, 200, 200
End Sub
However, this does not
VB Code:
Private Sub Form_Load()
'from Form_Load event
Me.AutoRedraw = True
LineTo Picture1.hdc, 200, 200
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.
-
Nov 28th, 2001, 01:29 PM
#3
Addicted Member
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
-
Nov 28th, 2001, 01:53 PM
#4
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
-
Nov 29th, 2001, 03:22 AM
#5
Thread Starter
Evil Genius
Wow, thanks guys, didn't know there was an autoredrawproperty for anything apart from the form
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|