Solved

Copy a picturebox to a picturebox on another form

Posted on 2000-02-16
4
373 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
  • 2
4 Comments
 

Accepted Solution

by:
genef earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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 …
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…
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 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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now