dcsimg
December 10, 2016
Hot Topics:

Beginning ActiveX - Part 2

  • November 19, 2002
  • By John Percival
  • Send Email »
  • More Articles »

Colours are stored in long-type variables, but you may have noticed that if you declare a property as long, you don't get the smart colour picker provided by VB.

The way to do this is in fact extraordinarily easy: all you need do is declare the property as type OLE_COLOR. And it goes a little something like this:

Public Property Get BackColor() As OLE_COLOR
BackColor = UserControl.BackColor
End Property

Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
UserControl.BackColor = New_BackColor
PropertyChanged "BackColor"
End Property

If you found that exciting, then you had better take a few deep breaths: it just gets better!

Do you remember back in depths of time (well, last week actually) that I mentioned in the first article that there was a third type of property procedure. It is the Property Set procedure, and it is used instead of the Property Let procedure for object variables. This is because the object variables that will store the object internally within the control will only store a reference to the object, not an actual replica. To differentiate this from an ordinary variable, VB uses the Set procedure. So what, you ask. Well, you may or may not know that both pictures and fonts are stored in objects. You probably will know that they have their own custom dialogs.

To use these dialogs, all we need do is declare the property as type Picture or Font, add the set procedure, then fire away. Just note that you must set the internal variable or, in this example, the internal control's property:

Public Property Get Font() As Font
Set Font = lblText.Font
End Property

Public Property Set Font(ByVal New_Font As Font)
Set lblText.Font = New_Font
PropertyChanged "Font"
End Property

As you can see, none of this is all that complicated. Let's have a look now at how to make some read-only properties.





Page 2 of 7



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel