areis0324 Posted December 26, 2008 Report Share Posted December 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
rkw6086 Posted December 26, 2008 Report Share Posted December 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
areis0324 Posted December 29, 2008 Author Report Share Posted December 29, 2008 ya~ thanks your kindly answer, this is really a stupid question. :-( I use this method as button1.BackColor=Color.FromName("#000000"); // It displays black correctly but Chart1.BackColor=button1.BackColor; // It displays nothing Anyway I have solved this trouble, thanks very much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.