RGB color in C# question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adrian

    RGB color in C# question

    Coding a website, one can create RGB colors with three pairs of two-digit
    hexadecimal values.
    How can one do that in C#?

    Many thanks.


  • Dennis Myrén

    #2
    Re: RGB color in C# question

    System.Drawing. Color c = System.Drawing. Color.FromArgb( /* R */ 0xFF, /* G
    */ 0xFF, /* B */ 0xFF);

    You can convert a HTML style color string to System.Drawing. Color like this:
    System.Drawing. Color c = System.Drawing. ColorTranslator .FromHtml("#FFF FFF");

    --
    Regards,
    Dennis JD Myrén
    Oslo Kodebureau
    "Adrian" <aa@aa.aa> wrote in message
    news:21f2$41616 6d7$3e159c2c$76 70@freeler.nl.. .[color=blue]
    > Coding a website, one can create RGB colors with three pairs of two-digit
    > hexadecimal values.
    > How can one do that in C#?
    >
    > Many thanks.
    >
    >[/color]


    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: RGB color in C# question

      Adrian,

      Yes, you can, but the thing is, what are you trying to do? Do you want
      a Color structure, or do you want a string?

      If you want a color structure, then you could convert each string into
      an int (using an overload of the static Parse method on the Int32 structure)
      and then pass those into the static FromArgb method of the Color structure.

      Hope this helps.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "Adrian" <aa@aa.aa> wrote in message
      news:21f2$41616 6d7$3e159c2c$76 70@freeler.nl.. .[color=blue]
      > Coding a website, one can create RGB colors with three pairs of two-digit
      > hexadecimal values.
      > How can one do that in C#?
      >
      > Many thanks.
      >
      >[/color]


      Comment

      • Adrian

        #4
        Re: RGB color in C# question

        "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
        message news:OZdzgTiqEH A.516@TK2MSFTNG P09.phx.gbl...[color=blue]
        > Adrian,
        >
        > Yes, you can, but the thing is, what are you trying to do?[/color]

        I want to make a little program for myself to help me get colors right
        when I am designing a website. Put the R, the G, and the B on slides
        and see what happens to the color. Display the value as composed.

        Actually, I believe Denis, who also responded, has answered my question
        rather well.

        However, thank you very much, Nicholas.


        Comment

        • Adrian

          #5
          Re: RGB color in C# question

          "Dennis Myrén" <dennis@oslokb. no> wrote in message
          news:3Kd8d.74$K m6.2170@news4.e .nsc.no...[color=blue]
          > System.Drawing. Color c = System.Drawing. Color.FromArgb( /* R */ 0xFF, /* G
          > */ 0xFF, /* B */ 0xFF);
          >
          > You can convert a HTML style color string to System.Drawing. Color like[/color]
          this:[color=blue]
          > System.Drawing. Color c =[/color]
          System.Drawing. ColorTranslator .FromHtml("#FFF FFF");[color=blue]
          >
          > --
          > Regards,
          > Dennis JD Myrén
          > Oslo Kodebureau[/color]

          Thank you very much. This is the sort of thing I was looking for.
          Regards,
          Adrian.


          Comment

          Working...