Results 1 to 3 of 3

Thread: casting problem

  1. #1

    Thread Starter
    Junior Member husain's Avatar
    Join Date
    Jul 2002
    Location
    United Arab Emirates
    Posts
    31

    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.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.

  3. #3

    Thread Starter
    Junior Member husain's Avatar
    Join Date
    Jul 2002
    Location
    United Arab Emirates
    Posts
    31
    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
  •  



Click Here to Expand Forum to Full Width