Solved

Copy a picturebox to a picturebox on another form

Posted on 2000-02-16
4
382 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
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

791 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