Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Copy a picturebox to a picturebox on another form

Posted on 2000-02-16
4
Medium Priority
?
409 Views
Last Modified: 2010-05-02
I want to copy the content of a picturebox all the object in the picturebox to another picturebox that is on another form! for example i have a mdichild with a picturebox and this picturebox have 3 textbox and when the copy is done all the 3 textbox is on the other form at the same position!
0
Comment
Question by:powlin
[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
  • 2
4 Comments
 

Accepted Solution

by:
genef earned 400 total points
ID: 2529053
Asuming you have Form1 with PictureBox
Picture1 and Form2 where you are going to copy it and call Picture2, the following code that is called from Form2 should do the trick:


Private Sub Command1_Click()
Dim ctrl As Control, strName As String
Call Form2.Controls.Add("VB.PictureBox", "Picture2")
With Me.Controls("Picture2")
    .Visible = True
    .Left = Form1.Picture1.Left
    .Top = Form1.Picture1.Top
    .Width = Form1.Picture1.Width
    .Height = Form1.Picture1.Height
End With
For Each ctrl In Form1.Controls
    If ctrl.Container.Name = "Picture1" Then
        strName = "VB." & TypeName(ctrl)
        Call Form2.Controls.Add(strName, ctrl.Name, Me.Controls("Picture2"))
        With Me.Controls(ctrl.Name)
            .Visible = True
            .Left = ctrl.Left
            .Top = ctrl.Top
            .Width = ctrl.Width
            .Height = ctrl.Height
        End With
    End If
Next
End Sub
0
 
LVL 5

Expert Comment

by:KDivad
ID: 2529907
That'll work in VB6, but as I recall, not 5 or down. To work in all of them, use control arrays. Instead of the Controls.Add, you would need

Load Text1(1)
Text1(1).SetParent Form2.Picture2 'Not sure, but it's close

HTH!
0
 

Expert Comment

by:genef
ID: 2532764
Thank you KDivad,
I agree, my answer will work only with VB6. With VB5, there is no complete solution, i.e. if you don't know the types of controls that are copied within Picture Box from one form to another then you cannot implement the asked functionality.
If on the other hand the types of controls are completely known, then the solution is quite simple:
You just need to put on the second form invisible Picture Box with one invisible control of every type within it, and set Index properties of the invisible controls to 0. Then, new controls may be added to the array using Load keyword, but there is no need to set Parent of them, just make them visible and adjust sizes as in the example within "Answer".
0
 
LVL 1

Author Comment

by:powlin
ID: 2533232
I have a problem the picturebox is created but when adding the objet in the picture box i receive an error
on this line
  Controls.Add strName, ctrl.Name, Me.Controls("Picture2")

Invalid Class String
Looking for object with ProgID: VB.Listview

strName = "VB.Listview"
ctrl.Name = "Listview"
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

618 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