How to construct System.Drawing.Color?

  • Thread starter Thread starter Klaus Bonadt
  • Start date Start date
K

Klaus Bonadt

I would like to retrieve Color settings, serialize them via XML and
construct the Color struct afterwards in order to use
RichTextBox.SelectionColor.

This would be easy if do not have to serialize the color, for example:
ColorDialog colorDialog1 = new ColorDialog();

// Set the initial color of the dialog to the current text color.
colorDialog1.Color = richTextBox1.SelectionColor;

// Determine if the user clicked OK in the dialog and that the color has
changed.
if(colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
colorDialog1.Color != richTextBox1.SelectionColor)
{
// Change the selection color to the user specified color.
richTextBox1.SelectionColor = colorDialog1.Color;
}


However, I would like to store the Color settings. Therefore, I need to know
how to construct the Color struct.
Any ideas?

Klaus
 
The Color type is serializable so you can (de-)serialize it to and from XML
using SoapFormatter. If you serialize using your own method, you can
reconstruct it from r,g and b values using Color.FromArgb.

Regards, Jakob.
 
However, I would like to store the Color settings. Therefore, I need to
know
how to construct the Color struct.
Any ideas?

Color.FromArgb
Color.FromName
Color.FromKnownColor

Wiktor Zychla
 
Back
Top