Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

transferring controls from one form to another

Posted on 1999-01-18
6
Medium Priority
?
159 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 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

927 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