transferring controls from one form to another

Posted on 1999-01-18
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...
Question by:moonlightcyber
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

Expert Comment

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,

Accepted Solution

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.


Expert Comment

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'.
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.


Expert Comment

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

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

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

Author Comment

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

Author Comment

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.

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

718 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