-
casting problem
I have an XML file that stores a font name and font size that I retrieve and store into variables of type string.
Code:
string FontName = [ all_the_XML_objects ].Value;
string FontSize = [ all_the_XML_objects ].Value;
MessageBox.Show(FontName); // Shows Lucida Console
MessageBox.Show(FontSize); // Shows 9
System.Drawing.Font newFont = new System.Drawing.Font(FontName, (float) FontSize);
// While compiling, the above line gives an error:
// Cannot convert type 'string' to 'float'
I would be grateful if anyone could help me out with this.
-
Try something like:
float.Parse(FontSize)
I don't have a computer with VS.Net on it, so I can't try it out. I know the integer class has a parse method though.
-
Thanks. float.Parse() worked. I also got this from somewhere - it worked too.
Code:
System.Drawing.Font newFont = new System.Drawing.Font(FontName, Convert.ToSingle(FontSize));