Private Void Button#click ( Object Sender, eventargs E)
{
Colordialog color = New Colordialog ();
If (Color. showdialog () = Dialogresult. OK)
{
Button button = (Button) sender;
IntR, G, B;
R=Color. color. R;
G=Color. color. g;
B=Color. color. B;
// RGB color value
String Rgbstring = R. tostring ( " X2 " ) + G. tostring ( " X2 " ) + B. tostring ( " X2 " );
// color string Alpha + RGB
string colorstring = color. color. a. tostring ( " X2 " ) + rgbstring;
// button display text
button. text = " # " + rgbstring;
//Button background color
Button. backcolor=Color. color;
// Button font color (argb), which is the reversed color of the button background color.
String Forecolorstring
= " FF " + ( 255 - R). tostring ( " X2 " )
+ ( 255 - G). tostring ( " X2 " )
+ ( 255 - B). tostring ( " X2 " );
//Button font color
Button. forecolor=
System. Drawing. color. fromargb (Int. Parse (
Forecolorstring, system. Globalization. numberstyles. hexnumber ));
}
}