BP Forums
Generating a Random Color in Visual Basic .NET - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+----- Forum: Code Snippets (https://bpforums.info/forumdisplay.php?fid=18)
+----- Thread: Generating a Random Color in Visual Basic .NET (/showthread.php?tid=633)



Generating a Random Color in Visual Basic .NET - Macatone - 09-03-2012

Here is a helpful code snippit that I converted to Visual Basic .NET from Brandon's post in the Java forum.

This function returns a color with random red, green, and blue values.

Pastebin: http://pastebin.com/aS7hxDu5

[code2=vbnet]'This function returns a color with random red, green, and blue values

Function getRandomColor() As Color

Dim random As Random = New Random()
Return Color.FromArgb(random.Next(256), random.Next(256), random.Next(256))

End Function[/code2]


Re: Generating a Random Color in Visual Basic .NET - brandonio21 - 09-03-2012

Wow! I can't believe that I did not think to convert it from Java to VB.NET. Thanks!


Re: Generating a Random Color in Visual Basic .NET - manishshrestha60 - 09-03-2012

How do you convert this codes


Re: Generating a Random Color in Visual Basic .NET - Macatone - 09-04-2012

brandonio21 Wrote:Wow! I can't believe that I did not think to convert it from Java to VB.NET. Thanks!
No problem!


Re: Generating a Random Color in Visual Basic .NET - Macatone - 09-04-2012

manishshrestha60 Wrote:How do you convert this codes
I saw Brandon's post about generating a random color in Java, so I looked up how to do it in C#. Then, since I am familiar with Visual Basic .NET and C#, I was able to just change the syntax from C# to Visual Basic .NET.

You can also just use a code converter such as these:
http://www.developerfusion.com/tools/convert/csharp-to-vb/
http://converter.telerik.com/


Re: Generating a Random Color in Visual Basic .NET - manishshrestha60 - 09-04-2012

Thanks


Re: Generating a Random Color in Visual Basic .NET - Macatone - 09-04-2012

manishshrestha60 Wrote:Thanks
No problem!