err: Cannot implicitly convert type 'string' to 'System.Drawing.Co

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to take the background color of the form from a user's
preferences file stored in xml file.
I tried:
while(XmlRdr.Read())
{
//check the node type and look for the element type
//whose Name property is equal to bg_color.
if (XmlRdr.NodeType==XmlNodeType.Element&&XmlRdr.Name=="bg_color")
{
Form1 frmMain = new Form1();
frmMain.BackColor = XmlRdr.ReadString();
frmMain.ShowDialog();
}
}

and it replies me the error that is in the subject: Cannot implicitly
convert type 'string' to 'System.Drawing.Color'. Can someone please suggest
solution?

Thanks a lot
 
orit said:
frmMain.BackColor = XmlRdr.ReadString();
frmMain.ShowDialog();
}
}

and it replies me the error that is in the subject: Cannot implicitly
convert type 'string' to 'System.Drawing.Color'. Can someone please
suggest
solution?

Take a look at the 'Color.From*' methods ('BackColor = Color.From*(...)').
 
Thanks a lot,
I have tried:
frmMain.BackColor = Color.FromName(XmlRdr.Value);
and on run-time I get an unhandled exception: "This control does not support
transparent background colors"

What is the problem?
Thanks
 
orit said:
frmMain.BackColor = Color.FromName(XmlRdr.Value);
and on run-time I get an unhandled exception: "This control does not
support
transparent background colors"

Can you post a sample color value that is stored in the database?
 
Few samples (All created in the same way):
Color [Lime]
Color [Olive]
Color [A=255, R=255, G=128, B=255]

Thanks a lot
 
Back
Top