[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Color generator ASP.NET

Posted on 2007-08-01
5
Medium Priority
?
346 Views
Last Modified: 2013-11-07
Is there a asp.net random color generator function or .dll that I can include in my project that I can refer to create a randomly generated HTML color?

For instance, I'd like to be able to do this (if it existed):

ColorGenerator myColorGenerator = new ColorGenerator();
string color = myColorGenerator.getColor();  //returns a random HTML hex color code

0
Comment
Question by:jeremyduj
  • 4
5 Comments
 
LVL 14

Expert Comment

by:chinu1310
ID: 19612073
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19612148
If that doesn't work check this.
http://steveorr.net/articles/ImproveYourImages.aspx

Create 3 random numbers from 2 to 255 (R,G,B)
than create color from these three.

0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19612288
Tested and working

Insert System.Drawing

And this much.

Random random = new Random();
        int R = random.Next(225);
        int G = random.Next(225);
        int B = random.Next(225);

        Color RandomColor = Color.FromArgb(R,G,B);
0
 
LVL 14

Accepted Solution

by:
chinu1310 earned 2000 total points
ID: 19612378
I did not realize that you want it as html color.

Here is what you wanted.

Function to convert RGB to html
public static string ToHtml(System.Drawing.Color color)
    {
        return string.Concat("#", (color.ToArgb() & 0x00FFFFFF).ToString("X6"));
    }

Than use as i posted above

Random random = new Random();
        int R = random.Next(225);
        int G = random.Next(225);
        int B = random.Next(225);
        System.Drawing.Color color = new Color();
        color  =  Color.FromArgb(R, G, B);
        string htmlcolor = ToHtml(color);
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19612573
Easy way to get HTML colors:
   ColorTranslator.ToHtml(Color.Red)

Bob
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deletiā€¦
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question