|
-
Jan 14th, 2003, 03:08 PM
#1
Thread Starter
Junior Member
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.
-
Jan 14th, 2003, 04:49 PM
#2
PowerPoster
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.
-
Jan 15th, 2003, 12:09 AM
#3
Thread Starter
Junior Member
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));
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|