Is there a way (in VB6) to encapsulate a control within a form so that the consumers of the form cannot modify the properties of the control on that form?
e.g If I have a form named Form1
with a button named Command1
, how do I prevent consumers (of Form1
) from doing this:
Form1.Command1.Enable = True
I rather want to expose a method like EnableCommand()
and let the method decide whether it is a valid operation to enable the command or not.
Most other languages the control on a form is private by default, how can one make a control Private
in VB6?
No, there's no easy way. In VB.Net you can set the access modifier of the controls in the form designer, but you can't do that in VB6.
In a big application, you can subdivide the logic into separate components (typically DLLs). Then the other components wouldn't have access to the form at all, including its controls.