Reputation: 2815
I want to convert RGB string to hex-color code. For example :
string rgb = rgb(0, 0, 255);
From above RGB I want to get:
string hex = #0000FF;
Upvotes: 0
Views: 143
Reputation: 24382
Use the built in ColorTranslator.ToHtml
string hex = ColorTranslator.ToHtml(myColor);
Upvotes: 1
Reputation: 4703
Simply like this
string hex = "#" + rgb.R.ToString("X2") + rgb.G.ToString("X2") + rgb.B.ToString("X2");
Upvotes: 0