Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change internal property of a label in ActiveX control 1

Status
Not open for further replies.

deamforever

Programmer
Dec 27, 2007
1
NO
Hi, there,

I am new to VB and ActiveX. So forgive me if my words are not precise.

I want to build an ActiveX control (an .ocx file)in Visual Basic 6 . It has public properties X1,X2,X3,....,X10, all boolean type, and inside this control it is a Label called lblShow.

The function of this ocx is to change the color (backcolor and forecolor) of label lblShow, according to the combinations of X1~X10.

Now I use Public Prorperty Let/Get methods to access X1~X10, which should work fine, for example.

------------------------------------

Public Property Let X1(ByVal newBool As Boolean)
On Error GoTo HandleError
varX1 = newBool
PropertyChanged "X1"
Exit Property
HandleError:
Call ReportError("Let X1", Err.source, Err.Description, "", 0)
End Property

Public Property Get X1() As Boolean
On Error GoTo HandleError
X1 = varX1
Exit Property
HandleError:
Call ReportError("Get X1", Err.source, Err.Description, "", 0)
End Property
...
...
------------------------

Then I want to use varX1~varX10 to change color of lblShow. The logic should be something like

if(varX1 and varX3) lblShow.BackColor=Red
else if (varX2 and varX4) lblShow.BackColor=Yellow
else if ...
end if

But my question is, since I don't want to make a public property which is directly mapped to lblShow.BackColor, how and where shall I put the logic above? When this logic should be excuted?

Do I have to map the lblShow.BackColor to a public property?

Please help with a piece of sample code structure, so I can study and start with.

Thanks in advance!

Deam



 
No, you don't have to map the backcolor property. Just put the logic you describe in a private Sub and call it every time you do a property let for one of your x1 to x10 properties.

By the way, you set the BackColor property with color constants, e. g. lblShow.BackColor = vbRed.
 
>you set the BackColor property with color constants

Wouldn't it be great if you could type in the name of the colour you wanted, though. You know, enter Salmon and get
[highlight #FA8072] [/highlight].

Well, you can (more-or-less) ...
 
Add a reference to the Microsoft HTML Object Library

Code:
[blue]Public Function GetColourByName(strColor As String) As String
    Dim lp As Long
    With New HTMLDocument
        .bgColor = strColor
        ' Convert web colour format into VB colour format, just one of several potential methods
        GetColourByName = "&H"
        For lp = 6 To 2 Step -2
            GetColourByName = GetColourByName & Mid$(.bgColor, lp, 2)
        Next
    End With
End Function[/blue]

Then you can feed it names like

lavender, MistyRose, SeaGreen, SaddleBrown

and get appropriate RGB coloour codes out. They are returned as strings in this particular version, but they are easily cast to longs, e.g.

Form1.BackColor = GetColourByName("CornflowerBlue")



















Ok - here's a page with the various colour names on it (it was stumbling upon this page that originally inspired me to write the function)
 
I first played with HTML when I'd just turned 18, at the time one thing I (and my co-workers) found mildly amusing was seeing some of the colours that came up when you put non-colour related words in as colours. I remember some very apt colours appearing sometimes. When I saw this post I thought it would do the same, and as predicted it does [smile] Thanks strongm for reminding me of some of the funnies in my early programming days [smile]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
>non-colour related words ... and as predicted it does

Indeed it does :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top