XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

About char width....

Last post 04/11/2009 11:36 AM by Kevins. 5 replies.
  • 04/11/2009 9:11 AM

    About char width....

    hi, everybody !

    i am coming back! 

    now, i get a issue, the issue is i want to create a components of "TextBox", i am already can draw the focus in my textbox control.
    but, when i capture a char on keyboard, i must to calculating the offset for char and let the cursor behind.

    That's my issue ! is there any body can tell me, how can i calculate the width of char?

    for example : 

        i create a object of "SpriteFont" and i specify the property of "Font Size(value is : 14)" in this object.  how can i calculate the offset about this SpriteFont?


    i am waitting for you !

    thanks.

  • 04/11/2009 9:17 AM In reply to

    Re: About char width....

    use the .MeasureString(string) method of your SpriteFont object, maybe? I think that's what you're asking for.
  • 04/11/2009 9:20 AM In reply to

    Re: About char width....

    Use the MeasureString method from the SpriteFont class.

    For example:
    SpriteFont font; 
    [...] 
    font = Content.Load<SpiteFont>([...]); 
    [...] 
    string userInput = [...] 
    Vector2 userInputDimensions = font.MeasureString(userInput); 

  • 04/11/2009 11:27 AM In reply to

    Re: About char width....

    hi , BShields, thank you very much.

    i already get your demo code, i'll try it later.

    but, the method of ".MeasureString()" has return a object of "Vector2". how can i use this object to get the value of char width?


    i am waiting for you ~


    Thanks.

    Kevin.Jee
  • 04/11/2009 11:30 AM In reply to

    Re: About char width....

    Kevins:
    the method of ".MeasureString()" has return a object of "Vector2". how can i use this object to get the value of char width?

    The X coordinate of the vector has the width and the Y coordinate has the height.
    Three colors, endless fun ... Primary Attack
  • 04/11/2009 11:36 AM In reply to

    Re: About char width....

    i'll try it later, thank you very much.
Page 1 of 1 (6 items) Previous Next