Cloning controls is actually quite a tricky concept. As a result, Microsoft has never builtiu it in by default into COM component5s (and hence VB controls). A keyword search in this forum should pick up some of my commentary about this.
Having said that, if a control supports persistence then it is pretty easy to turn that into a cloning function (and there are a few vVB controls and classes that have a built-in cloning function
I found an extremely easy answer to this question: use control arrays. If you create one of the control you want to clone on your form and give it an index of 0 (i.e. make it part of a control array) you can clone it all day long by simply using the Load command:
Code:
x = theControl.Count
Load theControl(x)
It creats ALMOST a clone of the original control. The Visible property is always false, and any actual data it contains (i.e. Caption, Text, Value, List, etc.) is not cloned, but almost every other attribute is.
Here's a very good tutorial on creating controls at runtime, both via this method and by the Controls.Add method:
(my point being that if you'd hadn't mentioned creating a copy in the original post we'd have probably gone straight to .Load and Control.add, but I thought you were looking for something else)
Sorry about the mixup in terminology. I started coding in COBOL on punched cards. I'm still not as comfortable with OOP terminology as some of you are (especially in VB). I was describing what I wanted to do from a physical point of view: I've got a set of controls in a frame, and I wanted to be able to "copy" that frame and it's set of controls repeatedly. Using Load did the job quite handily.
I guess if I was REALLY going object oriented I could have made the whole set of controls and their frame a class, but that's a little beyond my current level of VB expertise.
Tracy Dryden
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.