Jump to content
Software FX Community

Chagne backcolor of chart


areis0324
 Share

Recommended Posts

Hi,

 I have a color-picker which will generate a color code as "#000000".

Now, I try to change backcolor of chart by this color code.

  Chart1.BackColor = System.Drawing.Color.FromName("#000000");

But nothing happened..... If try with

Chart1.BackColor = System.Drawing.Color.Black;

It works.

What I lost? Thanks a lot.

Link to comment
Share on other sites

It's because you're using the wrong method. :-)

System.Drawing.Color.FromName(string); only works with a name of a color like black, blue, red, orange, etc.... You're attempting to pass in a hexadecimal representation of a color so since the color name isn't a hexadecimal, the method returns pure white as a default.

Microsoft created a whole new method just for something like this. Instead of calling Color.FromName(string), call ColorTranslator.FromHtml(string), This will return you a color value based off your hexadecimal string.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...