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????????????
Printable View
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.
Code:Private Sub Command1_Click()
Text1.ForeColor = vbBlue
End Sub
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.
Megatron, that is true everywhere... Except Visual Basic ( :rolleyes: ) In vb, it is bbggrr.
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. ;)
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 ....
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.
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
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.
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.
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.
Nope. In vb, hex colors are entered &HBBGGRRQuote:
Originally posted by Megatron
I think the colors work something like this.
&hRRGGBB
R is Red, G is Green and B is blue.
It had me messed up for a while.
Hmm, i wondered why that sounded familiar :DQuote:
Originally posted by Lord Orwell
Megatron, that is true everywhere... Except Visual Basic ( :rolleyes: ) In vb, it is bbggrr.
Oops. :o didn't see that there. :D
The API functions seem to expect it as BBGGRR too :eek:
Slightly bizarre...oh well, blame Intel :p
Blame the guy that came up with web colors :D
Bitmaps store the color in bbggrr format also.
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: