How to use QBColor in VB.NET?

  • Thread starter Thread starter Kamlesh
  • Start date Start date
K

Kamlesh

Hi,

In VB6, on every click on Command1, to change the Form background
color dynamically, I use:

Private Sub Command1_Click()
Me.BackColor = QBColor(Rnd * 14)
End Sub



How can I achieve the same in .NET? When I am using QBColor()
function in .NET, it is giving the the following error:

Value of type 'Integer' cannot be converted to 'System.Drawing.Color'.


Regards,
Kamlesh
 
Hi, (untested) try:

Me.BackColor = Color.FromARGB(QBColor(Rnd * 14))

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
 
Hi,

Tom:
Color.FromARGB doesn't work. It gives run-time exception.

Cor:
My development environment is not showing the ToARGB method? Whats the
problem? The link sent by you says:

Syntax based on .NET Framework version 1.1.
Documentation version 1.1.1.

Does this mean that I need ver 1.1? How do know my .NET Framework
version?

Regards,
Kamlesh
 
Hi Kamlesh,

A combination by me from Toms work and MSDN

I did not really check what it does :-))

I hope this works as expected?

Cor

\\\
Dim someColor As Color = _
Color.FromArgb(QBColor(CInt(Rnd() * 14)))
Dim colorMatches(167) As KnownColor
Dim count As Integer = 0
Dim enumValue As KnownColor
For enumValue = 0 To KnownColor.YellowGreen
someColor = Color.FromKnownColor(enumValue)
If someColor.G <> 0 And someColor.R = 0 And _
Not someColor.IsSystemColor Then
colorMatches(count) = enumValue
count += 1
End If
Next
Me.BackColor = someColor
///
 
Hi,


These work. The exception you get is this control doesnt support
transparent colors. The QBColor doesn't come up with the right color code.

Dim c As Color = Color.FromArgb(-16776961)

Dim x As Integer = c.ToArgb()

Me.BackColor = c

Ken
 
Hi Ken/Cor,

I tried both of your code. The code is running without any errors. But
I want the Form Background color to change randomly on every click of
the Command Button.

Right now, with your sample code, it is showing only one single color.
The color is not changing on every click of the commandbutton.

Regards,
Kamlesh
 
Hi Kamlesh,

Will you try this

I thought it works as you wanted it?

Cor

\\\
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim b As Integer = CInt(167 * Rnd() + 1)
Me.BackColor = Color.FromKnownColor(CType(b, KnownColor))
End Sub
///
 
Heh.... caps lock got a bit stuck there...

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
 
Back
Top