Results 1 to 18 of 18

Thread: color.....

  1. #1
    Zambi
    Guest
    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????????????

  2. #2
    Guest
    You can use color constants VB has already set.


    Code:
    Private Sub Command1_Click()
        Text1.ForeColor = vbBlue
    End Sub

  3. #3
    Member susn's Avatar
    Join Date
    Feb 2001
    Location
    Dubai
    Posts
    48
    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

  4. #4
    Guest
    I think the colors work something like this.

    &hRRGGBB

    R is Red, G is Green and B is blue.

  5. #5
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    Megatron, that is true everywhere... Except Visual Basic ( ) In vb, it is bbggrr.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  6. #6
    New Member
    Join Date
    Jan 2001
    Posts
    14

    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

  7. #7
    Member susn's Avatar
    Join Date
    Feb 2001
    Location
    Dubai
    Posts
    48
    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 ....

  8. #8
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  9. #9
    Member susn's Avatar
    Join Date
    Feb 2001
    Location
    Dubai
    Posts
    48

    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

  10. #10
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  11. #11
    Member susn's Avatar
    Join Date
    Feb 2001
    Location
    Dubai
    Posts
    48

    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.

  12. #12
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  13. #13
    Lively Member
    Join Date
    Jun 2000
    Posts
    124
    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...

  14. #14
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  15. #15
    Lively Member
    Join Date
    Jun 2000
    Posts
    124
    Oops. didn't see that there.
    On Error Resume Screaming...

  16. #16
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  17. #17
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    Blame the guy that came up with web colors

    Bitmaps store the color in bbggrr format also.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  18. #18
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width