CodeItBetter Programming Another VB Programming Blog

How to Mix colors

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'Graphics - How to Mix colors
Option Explicit
 
Private Function MixColors(ParamArray lMix() As Variant) As Long
    Dim lR As Long, lG As Long, lB As Long
    Dim lNewR As Long, lNewG As Long, lNewB As Long
    Dim lColors() As Long
    Dim I As Integer
 
    ReDim lColors(UBound(lMix) + 1)
 
    For I = 0 To UBound(lMix)
        lColors(I) = lMix(I)
    Next I
 
    For I = 0 To UBound(lColors)
        Debug.Print lColors(I)
        lR = lColors(I) And 255
        lG = (lColors(I) And 65280) / 256
        lB = (lColors(I) And 16711680) / 65536
        lNewR = lNewR + lR
        lNewG = lNewG + lG
        lNewB = lNewB + lB
    Next I
 
    MixColors = RGB(lNewR / UBound(lColors) + 1, lNewG / UBound(lColors) + 1, _
        lNewB / UBound(lColors) + 1)
End Function
 
'How to use this function:
'Me.BackColor = MixColors(vbRed, vbYellow) 'produces an orange color

Related posts:

  1. How to Convert OLE colors to RGB colors
  2. How to make a Web Browser in Visual Basic 2008 part 2 of 2
  3. How to get the RGB value of a Color
  4. How to get the Pixel color outside your form
  5. How to converte color value(longint) into RGB value.
  6. How to replace a Color with another Color in Picture Box
  7. How to delete an item in an array
  8. How to color the words in Rich Text box automatically like VB Editor?
  9. How to change the background color of each of your TextBox controls to yellow when it receives the input focus and restore its background color to white when the user clicks on another field

Filed under: Graphics Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.