Problem Exposing Some Properties of Control Based on Textbox

Martin Liss
Martin Liss used Ask the Experts™
on
I have developed an ActiveX control that is based on a textbox. I find that some properties like Visible and Width are exposed by default but others like Multiline and Scrollbar are not. What do I need to do to expose them?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
These 2 properties read only at run-time so you can't do much!
I recommend running the VB ActiveX Control Interface wizard (which can be found in the add-ins).  It can be done after the fact of having built the control.  The screens will show you how to expose the constituent controls properties.
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Author

Commented:
OK, I ran the ActiveX Control Wizard and using it I added the MultiLine property and mapped it to the MultiLine property of the underlying textbox. That resulted in the code below being added to my project. However after compiling my ocx and adding the control to a form, I don't see MultiLine in the available properties.

'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=txtNumberBox,txtNumberBox,-1,MultiLine
Public Property Get MultiLine() As Boolean
    MultiLine = txtNumberBox.MultiLine
End Property
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
The Let property has not been generated because it is read-only at run-time!
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Author

Commented:
I understand that, but shouldn't I be able to see and change the property at *design* time, just like a normal textbox?
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
The thing you need to understand is that when you place your control onto a form, your control is already at run-time! This is why you can't change these properties.
What you can do is to provide all the types of controls on your user control.  Make sure all the richtextboxes have the same text inside them.

For example (assuming multiline is true/false and scrollbars is true/false)  I say this so you can use this technique for any kind of control where these problems exist:
4 RichTextBoxes RTB1, RTB2, RTB3, RTB4 and set their design-time properties as follows within your user control:

RTB1)  Multiline =False, Scrollbars = false
RTB2) Multiline = True, ScrollBars = false
RTB3) Multiline = False, , ScrollBars = true
RTB4) multiline = true, scrollbars = true


Provide your own Multiline and Scrollbars properties that are NOT linked to any richtextbox.

Thes properties can be design-time only or design/run time.
Then, when a property is set, check the 4 states and decide which RichTextBox to show.

Something like:
property set Multiline(bNewValue as boolean)
hide all richtextboxes
select case true
   case not multiline and not scrollbars
     show RTB1
   case Multiline and not scrollbars
     show RTB2
   case not multiline and scrollbars
     show RTB3

   Case Multiline and scrollbars
      show RTB4

end select

It ain't pretty, but it works.

Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Author

Commented:
What do I do then if I want the user to be able to set the MultiLine property?
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
>>What do I do then if I want the user to be able to set the MultiLine property?

I have read a book that talked about it while ago (in the VB5 era!) from Dan Appleman and what twalgrave described (having multiple controls into a your controls is one thing he suggested.
By exposing your own properties as public as I mentioned above for Scrollbars and Multiline, those properties now appear in the design-time list of properties for your control.

You can even turn the multi-ine property to one that is settable in both design-time and run-time using the method described above.

Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Author

Commented:
Thanks (everyone).

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial