• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

transferring controls from one form to another

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...
1 Solution
Have you tried to use the setparent API along with the controls collection? This might be an answer to your problem.

hope it helps,
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.

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'.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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.
moonlightcyberAuthor Commented:
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...
moonlightcyberAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now