Using PaintPicture without any Picture

Hi.

I want to "draw" on a PictureBox and then use the method
Picture1.PaintPicture to copy the drawings to another Picturebox.

But I can't do that.
If I try to "PaintPicture" without having assigned a picture to the source PictureBox first
I got "invalid Picture" and if I assign a picture and then make some drawing on it using Picture1.Line or Picture1.Pset the only thing that will be copied is the original picture, not my drawings.

Is it not possible to copy "drawings" between pictureboxes
using standard PictureBoxes rutines.

Per

PerBomanAsked:
Who is Participating?
 
WolfgangKoenigConnect With a Mentor Commented:
Complete is:
Private Sub Form_Load()
  ' Set AutoRedraw to True.
  Picture1.AutoRedraw = True
End Sub

Private Sub Picture1_Click()
' Declare variables.
  Dim PW, PH
' Set FillStyle to Solid.
  Picture1.FillStyle = vbFSSolid
' Choose random color.
  Picture1.FillColor = QBColor(Int(Rnd * 15))
  PW = Picture1.ScaleWidth   ' Set ScaleWidth.
  PH = Picture1.ScaleHeight   ' Set ScaleHeight.
  ' Draw a circle in random location.
  Picture1.Circle (Int(Rnd * PW), Int(Rnd * PH)), 250
End Sub

Private Sub Picture2_Click()
' Copy Image to Picture2.
Picture2.PaintPicture Picture1.Image, 0, 0
End Sub

Thats was it ...
WoK
0
 
Ryan ChongCommented:
Hi PerBoman,

Last 10 Grades Given C B C C C B B B B B  ..
0
 
WolfgangKoenigCommented:
You can use the properties Image and Picture to do this.
Here is an example:

This example draws a circle in the first PictureBox control each time you click it. When you click the second PictureBox, the graphic from the first PictureBox is copied into it. To try this example, paste the code into the Declarations section of a form that has two large, equal-sized PictureBox controls. Press F5 to run the program, and then click the PictureBox controls.

Private Sub Form_Load ()
   ' Set AutoRedraw to True.  
   Picture1.AutoReDraw = True
End Sub

Private Sub Picture1_Click ()
 ' Declare variables.
   Dim PW, PH
 ' Set FillStyle to Solid.
   Picture1.FillStyle = vbFSSolid  
 ' Choose random color.
   Picture1.FillColor = QBColor(Int(Rnd * 15))
   PW = Picture1.ScaleWidth   ' Set ScaleWidth.
   PH = Picture1.ScaleHeight   ' Set ScaleHeight.
   ' Draw a circle in random location.
   Picture1.Circle (Int(Rnd * PW), Int(Rnd * PH)), 250
End Sub

Private Sub Picture2_Click ()
 ' Copy Image to Picture2.
   Picture2.Picture = Picture1.Image
End Sub


Best regards
WoK
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
PerBomanAuthor Commented:
How do I do then if I only want to copy
a portion of the image?
(like one could in PaintPicture)
0
 
WolfgangKoenigCommented:
Use this:
Private Sub Form_Load()
 Picture2.PaintPicture Picture1.Image, 0, 0
End Sub

WoK
0
 
PerBomanAuthor Commented:
Thanks.

No I see that you do just like I have been doing, except
that you are using "Image" instead of "picture" as the first parameter to PaintPicture.

I was close but not enough.



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.