Re: Create Class and put new methods/property for a control
Originally Posted by DataMiser
Sounds like what you want is a user control
Sorry, but I do not want to buiild a new user control , only methods and property , The user must put in Reference inside project
, is only the class , but I do know how can to do It
Re: Create Class and put new methods/property for a control
Originally Posted by mutley
Hi
How can I to Reference a control inside Class and put new methods, How can I to Call this class and new methods and property ?
In your Class module you reference a control which will be on some Form (not in the Class module) like this:
Form1.control where control is a control on Form1. To reference one of it's properties you do this:
Form1.control.someproperty
I am assuming you already know how to set up your class
However, I don't think you are really asking about a class. I think you are asking about a user control and how do you reference the methods and properties of the uc
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: Create Class and put new methods/property for a control
But... you should never ever access a control on a form using the form name from a class module, defeats the purpose of using a class and limits it to only being able to work with that form.
Instead you should pass the form as a parameter so it will work no matter what the form name is.
That said if you want to extend a control by adding properties and methods then the simple solution is to create a user control
Re: Create Class and put new methods/property for a control
mutley,
Can you verify if you are using VB6 and not VB.NET?
In VB.NET what you are asking about is called inheritance.
VB6 does not support that directly.
There are work arounds.
A user control is one. You would have to map all the existing properties if you want them as well.
Another option is to create a class that incorporates a variable of the control type and exposes its events with the 'WithEvents' clause.
You would create a collection of instances of the class in form load attaching the relevant controls in a loop.
All in all it is a kludge, but it can solve some difficult problems. (I still use it occasionally in VBA.)
I can dig up a sample if this is what you want.
Burn the land and boil the sea
You can't take the sky from me
Re: Create Class and put new methods/property for a control
Originally Posted by Gruff
mutley,
Can you verify if you are using VB6 and not VB.NET?
In VB.NET what you are asking about is called inheritance.
VB6 does not support that directly.
There are work arounds.
A user control is one. You would have to map all the existing properties if you want them as well.
Another option is to create a class that incorporates a variable of the control type and exposes its events with the 'WithEvents' clause.
You would create a collection of instances of the class in form load attaching the relevant controls in a loop.
All in all it is a kludge, but it can solve some difficult problems. (I still use it occasionally in VBA.)
Re: Create Class and put new methods/property for a control
Originally Posted by DataMiser
But... you should never ever access a control on a form using the form name from a class module, defeats the purpose of using a class and limits it to only being able to work with that form.
Instead you should pass the form as a parameter so it will work no matter what the form name is.
That said if you want to extend a control by adding properties and methods then the simple solution is to create a user control
Yes, I know that but that was what I thought he was asking so I showed him even though I knew you should not do that (I give the benefit of doubt to the OP)
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: Create Class and put new methods/property for a control
There is a sort of inside-out way to do this where you write a Class where every method and property accepts a reference to the control to be "twiddled with" as a parameter. It only works well for some sorts of operations and can be very confusing for others to stumble upon in your code if they've never seen it before.
For example the attached TBX object demo shows such a Class used to implement "extended properties" for VB's intrinsic TextBox control. In this case the goal is to be able to use TextBox controls for huge amounts of text.
... where Text1 is a VB TextBox. There TBX.Length returns the size of the contents of the TextBox in characters, up to approx. 2 billion at least in theory.