Results 1 to 14 of 14

Thread: Make ButtonFace lighter [RESOLVED]

  1. #1

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125

    Make ButtonFace lighter [RESOLVED]

    Hey everyone. I am trying to make vbButtonFace a little lighter. I don't mean to change system colors or anything, but I want to take the constant vbButtonFace, then add or subtract some from it to make it darker or lighter and place it in my own variable. I've tried this:
    VB Code:
    1. Dim myColor As Long
    2. myColor = Val(vbButtonFace)+1000
    3. myButton.BackColor = myColor
    But it gives me an invalid property value. I want to do this with vbButtonFace instead of a constant color because sometimes people have different colors on their systems other than the default grey, and I want my buttons to stand out a little from the background. This way if they have 3D Objects in their system settings set to a dark blue, then my buttons will be a little lighter blue, and if they have a yellow, then the buttons will be a darker yellow, etc...

    Thanks for any help.
    Last edited by MidgetsBro; Oct 20th, 2002 at 08:59 PM.
    <removed by admin>

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Of course it will - you need to provide HEX number (&something&) or RGB value to change colors.
    Roy

  3. #3
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Try sth. like:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
    4. Private Const COLOR_BTNFACE = 15
    5.  
    6. Private Sub Command1_Click()
    7.     Dim ButtonFace As Long
    8.     Dim Red As Byte
    9.     Dim Blue As Byte
    10.     Dim Green As Byte
    11.    
    12.     ButtonFace = GetSysColor(COLOR_BTNFACE)
    13.     Red = ButtonFace And vbRed
    14.     Green = (ButtonFace And vbGreen) / (2 ^ 8)
    15.     Blue = (ButtonFace And vbBlue) / (2 ^ 16)
    16.    
    17.     ButtonFace = RGB(Red + 50, Green + 50, Blue + 50)
    18.    
    19.     Command1.BackColor = ButtonFace
    20. End Sub
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Originally posted by IROY55
    Of course it will - you need to provide HEX number (&something&) or RGB value to change colors.
    Tried that too, and it didn't work... I forgot to post that.

    VB Code:
    1. myColor = Hex(vbButtonFace) + Hex(1000)
    2. CommandButton.BackColor = myColor 'type mismatch
    <removed by admin>

  5. #5

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Thanks McBrain. That worked.
    <removed by admin>

  6. #6
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Be careful with the bounds!!
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  7. #7

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Originally posted by Mc Brain
    Be careful with the bounds!!
    Already got that one fixed.
    <removed by admin>

  8. #8
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I mean... if the Red component is 237 you won't be able to add 20, for example to enlighten it.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  9. #9

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Originally posted by Mc Brain
    I mean... if the Red component is 237 you won't be able to add 20, for example to enlighten it.
    Yes I know.

    VB Code:
    1. Public Sub LightenButtons(frm As Form)
    2. Dim ButtonFace As Long
    3. Dim Red As Byte
    4. Dim Blue As Byte
    5. Dim Green As Byte
    6.  
    7. ButtonFace = GetSysColor(COLOR_BTNFACE)
    8. Red = ButtonFace And vbRed
    9. Green = (ButtonFace And vbGreen) / (2 ^ 8)
    10. Blue = (ButtonFace And vbBlue) / (2 ^ 16)
    11. If Red > 240 Then
    12.   Red = 255
    13. Else
    14.   Red = Red + 15
    15. End If
    16. If Green > 240 Then
    17.   Green = 255
    18. Else
    19.   Green = Green + 15
    20. End If
    21. If Blue > 240 Then
    22.   Blue = 255
    23. Else
    24.   Blue = Blue + 15
    25. End If
    26. ButtonFace = RGB(Red, Green, Blue)
    27.  
    28. Dim ctl As Control
    29. For Each ctl In frm
    30.   If TypeOf ctl Is CommandButton Then
    31.     ctl.BackColor = ButtonFace
    32.   End If
    33. Next
    34. End Sub
    <removed by admin>

  10. #10
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    OK... it seems you've already got the idea and added all the IFs statements that I were too lazy to add.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  11. #11

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Yup. hehe. I wish I didn't have to use all those ifs, but it looks like the only way for right now. I'll think about making it better code later, but for now it works, and that's all that matters.

    Thanks again.
    <removed by admin>

  12. #12
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by MidgetsBro
    Yup. hehe. I wish I didn't have to use all those ifs, but it looks like the only way for right now. I'll think about making it better code later, but for now it works, and that's all that matters.

    Thanks again.
    You're welcome.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  13. #13
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    You can try:
    VB Code:
    1. Public Sub LightenButtons(frm As Form)
    2.     Dim ButtonFace As Long
    3.     Dim Red As Byte
    4.     Dim Blue As Byte
    5.     Dim Green As Byte
    6.    
    7.     ButtonFace = GetSysColor(COLOR_BTNFACE)
    8.     Red = ButtonFace And vbRed
    9.     Green = (ButtonFace And vbGreen) / (2 ^ 8)
    10.     Blue = (ButtonFace And vbBlue) / (2 ^ 16)
    11.    
    12.     Red = IIf(Red > 240, 255, Red + 15)
    13.     Green = IIf(Green > 240, 255, Green + 15)
    14.     Blue = IIf(Blue > 240, 255, Blue + 15)
    15.  
    16.     ButtonFace = RGB(Red, Green, Blue)
    17.    
    18.     Dim ctl As Control
    19.     For Each ctl In frm
    20.       If TypeOf ctl Is CommandButton Then
    21.         ctl.BackColor = ButtonFace
    22.       End If
    23.     Next
    24. End Sub
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  14. #14
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Or just this way:
    VB Code:
    1. Public Sub LightenButtons(frm As Form, Shift As Integer)
    2.     Dim ButtonFace As Long
    3.     Dim Red As Integer
    4.     Dim Blue As Integer
    5.     Dim Green As Integer
    6.    
    7.     ButtonFace = GetSysColor(COLOR_BTNFACE)
    8.     Red = (ButtonFace And vbRed) + Shift
    9.     Green = ((ButtonFace And vbGreen) / (2 ^ 8)) + Shift
    10.     Blue = ((ButtonFace And vbBlue) / (2 ^ 16)) + Shift
    11.  
    12.     ButtonFace = RGB(Red, Green, Blue)
    13.    
    14.     Dim ctl As Control
    15.     For Each ctl In frm
    16.       If TypeOf ctl Is CommandButton Then
    17.         ctl.BackColor = ButtonFace
    18.       End If
    19.     Next
    20. End Sub
    Apparently, if the number is bigger than 255, the RGB would use 255 instead. So, there's no need to check if it's bigger than 255. However, you have to declare the variables as Integer, instead of Byte.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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