Solved

Copy a picturebox to a picturebox on another form

Posted on 2000-02-16
4
390 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 200 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

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!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

717 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