
Introduction
This Application will show the Format of the current selected color in three Formats i.e RGB Format, Hexadecimal Format and Interger Format. You can change the value of any format, the other formats will adjust by themself.
System.Drawing.Color
This namespace almost provide all the colors used in the daily life Applications, if you want to make your own color, then this namespace provide the following fucntion.
Color.FromArgb : Creates a Color structure from the four 8-bit ARGB component (alpha, red, green, and blue) values.
Hexadecimal Conversion
A integer value of the RBG Color can be obtained from the
Color.FromArgb(int argb) Function. Now the Following code will convert the Decimal Representation into Hexadeciaml Representation.
private string DeciamlToHexadeciaml(int number)
{
string[] hexvalues={"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
string result=null, final=null;
int rem=0,div=0;
while(true)
{
rem=(number%16);
result+=hexvalues[rem].ToString();
if (number<16)
break;
number=(number/16);
}
for (int i=(result.Length-1); i>=0; i--)
{
final+=result[i];
}
return final;
}
Current Color
The current color Box will show the current color selected within different formats. Current Color is displayed with the help of Picture Box.
this.pictureBox1.BackColor=Color.FromArgb(Convert.ToInt32(this.RedValue.Text),Convert.ToInt32(this.GreenValue.Text),Convert.ToInt32(this.BlueValue.Text));
Decimal Conversion
When the change is made to the integer value of RGB Color, then this integer value is changed into the corresponding Hexadecimal Value
private int GetNumberFromNotation(char c)
{
if (c=='A')
return 10;
else if (c=='B')
return 11;
else if (c=='C')
return 12;
else if (c=='D')
return 13;
else if (c=='E')
return 14;
else if (c=='F')
return 15;
return Convert.ToInt32(c.ToString());
}
private int HexadecimaltoDecimal(string hexadecimal)
{
int result=0;
for (int i=0; i<hexadecimal.Length; i++)
{
result+=Convert.ToInt32(this.GetNumberFromNotation(hexadecimal[i])*Math.Pow(16,Convert.ToInt32(hexadecimal.Length)-(i+1)));
}
return Convert.ToInt32(result);
}
Motivation
The Idea of making this program comes when i get fustrated, this is the time when i was working on different Graphical Tools, the problem there is that some support the RDB Color Format, some support Hexadecimal Format and others....
So instead of calculating again & again, i have this nice program on my desktop now :).
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.