Solved

transferring controls from one form to another

Posted on 1999-01-18
6
156 Views
Last Modified: 2010-05-03
hello...i have 8 pic boxes on my main form, they serve as resizing handles....i need to use these handles on other forms as well, do i have to copy all the controls to the other forms, or is there another way, without having to copy contyrols and paste them on a form..maybe with a class...
thanks
0
Comment
Question by:moonlightcyber
6 Comments
 
LVL 1

Expert Comment

by:rondeauj
ID: 1469272
Have you tried to use the setparent API along with the controls collection? This might be an answer to your problem.

hope it helps,
0
 
LVL 1

Accepted Solution

by:
hddp666 earned 100 total points
ID: 1469273
If you open the main form's file (Form1.frm) using a text editor like Notepad, you will be able to see the code for the controls. This code is hidden in the VB environment.

The controls' portion of the code that you want to import into another form can be easily cut and pasted using the text editor, or you can write a simple program that will take an existing form, and add the controls' code to it.

Another thing you can do is create a new form with only the pic box controls on it, and then save it and rename/copy it to the vb\templates directory. When you want to create a new form with the pic boxes, open the existing form and save it as the new form name.

0
 
LVL 3

Expert Comment

by:vbWhiz
ID: 1469274
Another option is to create a 'UserControl' containing the 8 picture boxes. You can then treat all 8 as one control. Place the control on any form you want. Use events to tell the form when to respond & what to do. All the code for the picture boxes will be encapsulated in the one 'UserControl'. Any modifications made to the 'UserControl' will modify the control you placed on all the forms. For all practical purposes, a 'UserControl' is a visible class. You can easily 'subclass' other controls capabilities & 'encapsulate' all the code written for this visible component in the 'usercontrol'.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Expert Comment

by:Johnn
ID: 1469275
Or, as long as your not going to need them on more than one form at a time at runtime you can use setparent api, just make sure before any form that's unloaded doesn't still have these "setparent" controls on them otherwise...your toast

for a=0 to 7
    setparent picture1(a).hwnd,newForm.hwnd
next

make sure you reset set them like this before unloading a form that has them on it

for a=0 to 7
    setparent picture1(a).hwnd,0
next

PS  If you accept this comment as the answer you were looking for, please let me know because I would appreciate the points.
0
 

Author Comment

by:moonlightcyber
ID: 1469276
thankyou for your answer hddp666,  i have made it work now..!!
but i think i am going to create a user control for it...seems mor efficient....thankyou for your comment vbWhiz...
0
 

Author Comment

by:moonlightcyber
ID: 1469277
johnn, i have already given the poiints away...and i think i am going to use your method, saves me having to create a control. because i don't need them on more than one form at a time....
unhfortunately you replied after i had given the points...but i won't forget.
thankyou
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

808 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