Translate language......
-
Can someone help me to translate the VB code into C#? I can't get the Mid & Right function of VB in C#.. wonder how... Color.FromArgb(Val("&h" & Mid(RGBColor, 1, 2)), Val("&h" & Mid(RGBColor, 3, 2)), Val("&h" & Mid(RGBColor, 5, 2))) Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2) Million thanks....
-
Can someone help me to translate the VB code into C#? I can't get the Mid & Right function of VB in C#.. wonder how... Color.FromArgb(Val("&h" & Mid(RGBColor, 1, 2)), Val("&h" & Mid(RGBColor, 3, 2)), Val("&h" & Mid(RGBColor, 5, 2))) Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2) Million thanks....
The direct translation would be:
using System.Globalization;
...
Color c = Color.FromArgb(
int.Parse(RGBColor.Substring(0, 2), NumberStyles.HexNumber),
int.Parse(RGBColor.Substring(2, 2), NumberStyles.HexNumber),
int.Parse(RGBColor.Substring(4, 2), NumberStyles.HexNumber));string s = Convert.ToString(c.R, 16).PadLeft(2, '0')
+ Convert.ToString(c.G, 16).PadLeft(2, '0')
+ Convert.ToString(c.B, 16).PadLeft(2, '0');A better solution would be to use the
ColorTranslator
class:Color c = ColorTranslator.FromHtml("#" + RGBColor);
string s = ColorTranslator.ToHtml(c).Substring(1);
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer