Click to See Complete Forum and Search --> : color.....
Zambi
Mar 1st, 2001, 09:01 AM
How can i enable a commandbutton to set the font color of text in my textbox ? I know the hexadecimal color codes but i don't know how to use them to change the font color of my text. can someone please help me????????????
You can use color constants VB has already set.
Private Sub Command1_Click()
Text1.ForeColor = vbBlue
End Sub
susn
Mar 1st, 2001, 01:56 PM
Option Explicit
Private Sub Command1_Click()
Text1.ForeColor = vbBlue
End Sub
'Color
'The following color constants can be used anywhere in your code in place of actual values:
'
'Constant Value Description
'vbBlack &h00 Black
'vbRed &hFF Red
'vbGreen &hFF00 Green
'vbYellow &hFFFF Yellow
'vbBlue &hFF0000 Blue
'vbMagenta &hFF00FF Magenta
'Cyan &hFFFF00 Cyan
'vbWhite &hFFFFFF White
I think the colors work something like this.
&hRRGGBB
R is Red, G is Green and B is blue.
Lord Orwell
Mar 2nd, 2001, 01:30 AM
Megatron, that is true everywhere... Except Visual Basic ( :rolleyes: ) In vb, it is bbggrr.
Xyanth
Mar 2nd, 2001, 10:19 AM
Why not use the RGB Function?
Just an example:
Private Sub Command1_Click()
Text1.ForeColor = RGB(Text2.Text, Text3.Text, Text4.Text)
End Sub
And if you have 3 other text boxes set up, you can make the color of the text box customizable for whoever is using it.. You can add a little more code to prevent the use of letters so there's no accidental error. ;)
susn
Mar 2nd, 2001, 12:30 PM
The Parameters for RGB(255, 255, 255)
First for Red, then for Blue, then for Green.
Expect the Color you will get from this Call is ..... White.
Try to set them to RGB(0, 0, 0) and you will get Black.
You can use it as following:
Private Sub Command1_Click()
Text1.ForeColor = RGB(0, 0, 0)
End Sub
Not TEXT1 ..... TEXT2 .... and so on ....
Lord Orwell
Mar 3rd, 2001, 01:50 AM
his code was valid. He just was reading the properties in the rgb function of 3 text boxes. each having a text typed value of 0-255.
And it's Blue, green, red. No matter what format you find the colors in, web, vb, monitor, etc., green is always the center color.
susn
Mar 3rd, 2001, 05:20 AM
I ve tryed it out and there was no way to run the Code.
I am interested in how you resolve this.
May sending me an Example Lord Orwell?
You can do it that way:
Private Sub Command1_Click()
Text1.ForeColor = RGB(0, 0, 0)
Text2.ForeColor = RGB(255, 0, 0)
Text3.ForeColor = RGB(0, 255, 0)
Text4.ForeColor = RGB(0, 0, 255)
End Sub
The Datatype of the Parameters must be Integer.
Greetz,
Susn
Lord Orwell
Mar 3rd, 2001, 01:28 PM
yes it must be. But his code wasn't set up to set the forecolor of all 4 text boxes. It set the color of one based on 3 integers entered in the other 3. Maybe it would have been clearer (and future proof) if he had made it like this: text1.forecolor = rgb(text2.text, tex3.text, text4.text).
now this may not work. It is hard to tell when vb will convert textboxes to integer values. Sometimes it does, sometimes it doesn't. So this would work:
text1.forecolor = rgb(val(text2.text), val(text3.text), val(text4.text))
I use the rgb function sometimes, but if you are just assigning a value, it is easier just to use the number in hex. text1.forecolor = &Hff0000 would set text1.forecolor to blue. &H00ff00 would be light green.
&H0000ff is red. &Hff00ff is purple, etc.
susn
Mar 3rd, 2001, 04:33 PM
To use this Function like this is to shoot from behind trough the shoulder in the Head trough the Eye.
Test it out.
When u use it like you wrote the Value of all three would be 0 and that improves that the Color would be black again ....
Now where is the praktikal use to?
Only because a Code looks very strange not improving to be very usefull.
Lord Orwell
Mar 3rd, 2001, 06:19 PM
the obvious use would be for a custom form for generating web colors. You could enter the red and blue and green values. It would show you the new color. If it is too green or whatever, you lower the green # a little and try again. Personally, i would use up and down arrows to change the # as well as the option to type it straight in.
DarkJedi9
Mar 3rd, 2001, 09:46 PM
Originally posted by Megatron
I think the colors work something like this.
&hRRGGBB
R is Red, G is Green and B is blue.
Nope. In vb, hex colors are entered &HBBGGRR
It had me messed up for a while.
Lord Orwell
Mar 3rd, 2001, 10:09 PM
Originally posted by Lord Orwell
Megatron, that is true everywhere... Except Visual Basic ( :rolleyes: ) In vb, it is bbggrr.
Hmm, i wondered why that sounded familiar :D
DarkJedi9
Mar 3rd, 2001, 10:13 PM
Oops. :o didn't see that there. :D
parksie
Mar 6th, 2001, 12:33 PM
The API functions seem to expect it as BBGGRR too :eek:
Slightly bizarre...oh well, blame Intel :p
Lord Orwell
Mar 6th, 2001, 04:34 PM
Blame the guy that came up with web colors :D
Bitmaps store the color in bbggrr format also.
parksie
Mar 6th, 2001, 04:39 PM
The problem seems to be endian formats :rolleyes: I've lost track of the number of times things like this have turned round and given me a hefty kick in the teeth :mad:
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.