Solved

Using PaintPicture without any Picture

Posted on 2001-09-03
6
507 Views
Last Modified: 2008-02-01
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

0
Comment
Question by:PerBoman
  • 3
  • 2
6 Comments
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 6450202
Hi PerBoman,

Last 10 Grades Given C B C C C B B B B B  ..
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6450285
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
 

Author Comment

by:PerBoman
ID: 6450359
How do I do then if I only want to copy
a portion of the image?
(like one could in PaintPicture)
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6450517
Use this:
Private Sub Form_Load()
 Picture2.PaintPicture Picture1.Image, 0, 0
End Sub

WoK
0
 
LVL 4

Accepted Solution

by:
WolfgangKoenig earned 200 total points
ID: 6450520
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
 

Author Comment

by:PerBoman
ID: 6450882
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question