Solved

Copy a picturebox to a picturebox on another form

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

697 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