|
-
Oct 20th, 2002, 08:39 PM
#1
Thread Starter
PowerPoster
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:
Dim myColor As Long
myColor = Val(vbButtonFace)+1000
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>
-
Oct 20th, 2002, 08:47 PM
#2
PowerPoster
Of course it will - you need to provide HEX number (&something&) or RGB value to change colors.
-
Oct 20th, 2002, 08:50 PM
#3
Need-a-life Member
Try sth. like:
VB Code:
Option Explicit
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Private Const COLOR_BTNFACE = 15
Private Sub Command1_Click()
Dim ButtonFace As Long
Dim Red As Byte
Dim Blue As Byte
Dim Green As Byte
ButtonFace = GetSysColor(COLOR_BTNFACE)
Red = ButtonFace And vbRed
Green = (ButtonFace And vbGreen) / (2 ^ 8)
Blue = (ButtonFace And vbBlue) / (2 ^ 16)
ButtonFace = RGB(Red + 50, Green + 50, Blue + 50)
Command1.BackColor = ButtonFace
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.
-
Oct 20th, 2002, 08:50 PM
#4
Thread Starter
PowerPoster
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:
myColor = Hex(vbButtonFace) + Hex(1000)
CommandButton.BackColor = myColor 'type mismatch
-
Oct 20th, 2002, 08:59 PM
#5
Thread Starter
PowerPoster
Thanks McBrain. That worked.
-
Oct 20th, 2002, 09:00 PM
#6
-
Oct 20th, 2002, 09:02 PM
#7
Thread Starter
PowerPoster
Originally posted by Mc Brain
Be careful with the bounds!!
Already got that one fixed.
-
Oct 20th, 2002, 09:03 PM
#8
-
Oct 20th, 2002, 09:12 PM
#9
Thread Starter
PowerPoster
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:
Public Sub LightenButtons(frm As Form)
Dim ButtonFace As Long
Dim Red As Byte
Dim Blue As Byte
Dim Green As Byte
ButtonFace = GetSysColor(COLOR_BTNFACE)
Red = ButtonFace And vbRed
Green = (ButtonFace And vbGreen) / (2 ^ 8)
Blue = (ButtonFace And vbBlue) / (2 ^ 16)
If Red > 240 Then
Red = 255
Else
Red = Red + 15
End If
If Green > 240 Then
Green = 255
Else
Green = Green + 15
End If
If Blue > 240 Then
Blue = 255
Else
Blue = Blue + 15
End If
ButtonFace = RGB(Red, Green, Blue)
Dim ctl As Control
For Each ctl In frm
If TypeOf ctl Is CommandButton Then
ctl.BackColor = ButtonFace
End If
Next
End Sub
-
Oct 20th, 2002, 09:15 PM
#10
Need-a-life Member
-
Oct 20th, 2002, 09:23 PM
#11
Thread Starter
PowerPoster
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.
-
Oct 20th, 2002, 09:51 PM
#12
-
Oct 20th, 2002, 10:03 PM
#13
Need-a-life Member
You can try:
VB Code:
Public Sub LightenButtons(frm As Form)
Dim ButtonFace As Long
Dim Red As Byte
Dim Blue As Byte
Dim Green As Byte
ButtonFace = GetSysColor(COLOR_BTNFACE)
Red = ButtonFace And vbRed
Green = (ButtonFace And vbGreen) / (2 ^ 8)
Blue = (ButtonFace And vbBlue) / (2 ^ 16)
Red = IIf(Red > 240, 255, Red + 15)
Green = IIf(Green > 240, 255, Green + 15)
Blue = IIf(Blue > 240, 255, Blue + 15)
ButtonFace = RGB(Red, Green, Blue)
Dim ctl As Control
For Each ctl In frm
If TypeOf ctl Is CommandButton Then
ctl.BackColor = ButtonFace
End If
Next
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.
-
Oct 20th, 2002, 10:10 PM
#14
Need-a-life Member
Or just this way:
VB Code:
Public Sub LightenButtons(frm As Form, Shift As Integer)
Dim ButtonFace As Long
Dim Red As Integer
Dim Blue As Integer
Dim Green As Integer
ButtonFace = GetSysColor(COLOR_BTNFACE)
Red = (ButtonFace And vbRed) + Shift
Green = ((ButtonFace And vbGreen) / (2 ^ 8)) + Shift
Blue = ((ButtonFace And vbBlue) / (2 ^ 16)) + Shift
ButtonFace = RGB(Red, Green, Blue)
Dim ctl As Control
For Each ctl In frm
If TypeOf ctl Is CommandButton Then
ctl.BackColor = ButtonFace
End If
Next
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|