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

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
 
H

Herfried K. Wagner [MVP]

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*(...)').
 
G

Guest

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
 
H

Herfried K. Wagner [MVP]

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?
 
G

Guest

Few samples (All created in the same way):
Color [Lime]
Color [Olive]
Color [A=255, R=255, G=128, B=255]

Thanks a lot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top