Solved

Copying picture boxes

Posted on 2001-07-24
17
163 Views
Last Modified: 2010-05-02
When I use something like Picture1.Line to make a line in a picturebox, and then I try to copy the contents of Picture1, to an icon or to Picture2, using Picture2.Picture = Picture1.Picture.  Why is it that the line I just made isn't copied?  Is there some other method I should be using instead of picture2=picture1?
0
Comment
Question by:Crash2100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
  • +3
17 Comments
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6315018
Try this...

Set Picture2 = Picture1
0
 
LVL 18

Author Comment

by:Crash2100
ID: 6315060
still does the same thing
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6315204
Set AutoRedraw = True on both picture boxes.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:JonFish85
ID: 6315207
try something like:

Picture2.PaintPicture Picture1.Picture
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6315225
Private Sub Command1_Click()
    Picture1.AutoRedraw = True
    Picture2.AutoRedraw = True
    Picture1.Line (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight)
    Set Picture2.Picture = Picture1.Image
    Picture2.Refresh
End Sub
0
 
LVL 28

Expert Comment

by:Ark
ID: 6315278
Hi
Just to explain:
When you use Picture1=Picture2 you use default property (Picture1.Picture = Picture2.Picture)
Picture property is what you set at design time and/or explicity set at run time. All your drawings store in .Image property.
So, you need

   Set Picture2.Picture = Picture1.Image
or
   Set Picture1.Picture = Picture1.Image
   Picture2 = Picture1

Cheers
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6315282
PaulHews seems to be correct.  The difference is in using the "image" property of the picturebox (which holds the current image) rather than the "picture" property (which holds a reference to a memory location that holds the image.)

It seems silly that only one works and not the other, but that's how it works sometimes.
0
 
LVL 18

Author Comment

by:Crash2100
ID: 6315306
ok, I see how I can copy the contents of picture1 to picture2.  How would I go about copying the contents of Picture1 to the icon of the form.  Because when I try something like below I get the error "Invalid property value."
 Picture1.Circle (0, 0), 500
 Picture1.Picture = Picture1.Image
 Me.Icon = Picture1.Picture
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6315317
You'll nice that if you go to that property and try to load an icon from windows, your only selections are .ico and .cur types, not bitmaps.

I think you need to save the bitmap image as an icon, then try loading it in.
0
 
LVL 18

Author Comment

by:Crash2100
ID: 6315369
so there's no way I can somehow create an icon from within visual basic?  the main reason I wanted to do this is so I could create an animated icon for my form.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6315411
Well, I'm not sure, but if you make the bitmap no more than 32x32 and save it with an .ico extension, it make actually work.  It still saves it as a bitmap, but Windows seems to recognize this as a cheap knock-off icon.
0
 
LVL 28

Accepted Solution

by:
Ark earned 50 total points
ID: 6315415
Hi
Add ImageList to your form:

Private Sub Command1_Click()
  Picture1.AutoRedraw = True
  Picture1.Line (0, 0)-(Picture1.Width, Picture1.Height)
  ImageList1.ListImages.Clear
  ImageList1.ListImages.Add , , Picture1.Image
  Set Icon = ImageList1.ListImages(1).ExtractIcon
End Sub

Cheers
0
 
LVL 18

Author Comment

by:Crash2100
ID: 6315416
I know if you save it as a .ico that it will recognize it as an icon, but I would prefer to not have to save the files (if possible), just to dynamically create the picture in the program and immediately put it up in the form's icon.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6315489
I thought this was about copying picture boxes, but it's actually about copying icons?  Ark has the answer there for you.
0
 
LVL 18

Author Comment

by:Crash2100
ID: 6315657
Ark, sorry, I didn't notice your comment the first time.  So, the only way to get my picture to the icon, is to first put it into an image list?  If so, why is this?
0
 
LVL 28

Expert Comment

by:Ark
ID: 6315681
Icon and Bitmap format are different. Form.Icon property accept only Icons.
There is an API way to convert bitmap to Icon, but it's long and hard. The easiest way is to use ImageList.

Cheers
0
 
LVL 18

Author Comment

by:Crash2100
ID: 6319578
thanks for all the help!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

689 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