|
|
Title | Generate random colors in VB .NET |
Description | This example shows how to generate random colors in VB .NET. |
Keywords | color, random color, QBColor, FromArgb, VB.NET |
Categories | Graphics, VB.NET |
|
|
Module RandomColors contains two functions that return random colors. Function RandomQBColor selects a random number between 0 and 15 and looks up the corresponding QBColor value. It adds an alpha component of &HFF000000 to the result and uses the Color.FromArgb method to convert the numeric value into a Color.
Function RandomRGBColor randomly generates random red, green, and blue components for a color.
|
|
Module RandomColors
Private m_Rnd As New Random
' Return a random QB color.
Public Function RandomQBColor() As Color
Dim color_num As Integer = m_Rnd.Next(0, 15)
Return Color.FromArgb(QBColor(color_num) + _
&HFF000000)
End Function
' Return a random RGB color.
Public Function RandomRGBColor() As Color
Return Color.FromArgb(255, _
m_Rnd.Next(0, 255), _
m_Rnd.Next(0, 255), _
m_Rnd.Next(0, 255))
End Function
End Module
|
|
|
|
|
|