|
-
Mar 1st, 2001, 10:01 AM
#1
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????????????
-
Mar 1st, 2001, 02:54 PM
#2
You can use color constants VB has already set.
Code:
Private Sub Command1_Click()
Text1.ForeColor = vbBlue
End Sub
-
Mar 1st, 2001, 02:56 PM
#3
Member
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
-
Mar 1st, 2001, 03:20 PM
#4
I think the colors work something like this.
&hRRGGBB
R is Red, G is Green and B is blue.
-
Mar 2nd, 2001, 02:30 AM
#5
Megatron, that is true everywhere... Except Visual Basic ( ) In vb, it is bbggrr.
-
Mar 2nd, 2001, 11:19 AM
#6
New Member
Prr¿
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.
"Curiosity killed the cat, but he still has eight lives left."
- Xyanth
"The only stupid question is the question never asked."
- Xyanth
-
Mar 2nd, 2001, 01:30 PM
#7
Member
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 ....
-
Mar 3rd, 2001, 02:50 AM
#8
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.
-
Mar 3rd, 2001, 06:20 AM
#9
Member
Cant Imagine
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
-
Mar 3rd, 2001, 02:28 PM
#10
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.
-
Mar 3rd, 2001, 05:33 PM
#11
Member
Color
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.
-
Mar 3rd, 2001, 07:19 PM
#12
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.
-
Mar 3rd, 2001, 10:46 PM
#13
Lively Member
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.
On Error Resume Screaming...

-
Mar 3rd, 2001, 11:09 PM
#14
Originally posted by Lord Orwell
Megatron, that is true everywhere... Except Visual Basic ( ) In vb, it is bbggrr.
Hmm, i wondered why that sounded familiar
-
Mar 3rd, 2001, 11:13 PM
#15
Lively Member
Oops. didn't see that there.
On Error Resume Screaming...

-
Mar 6th, 2001, 01:33 PM
#16
Monday Morning Lunatic
The API functions seem to expect it as BBGGRR too 
Slightly bizarre...oh well, blame Intel
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 6th, 2001, 05:34 PM
#17
Blame the guy that came up with web colors 
Bitmaps store the color in bbggrr format also.
-
Mar 6th, 2001, 05:39 PM
#18
Monday Morning Lunatic
The problem seems to be endian formats I've lost track of the number of times things like this have turned round and given me a hefty kick in the teeth
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|