Results 1 to 5 of 5

Thread: drawing sentered text?!

  1. #1

    drawing sentered text?!

    I dont know if there is something about this out on the forum. i looked for it, but didnt find anything useful.

    I need to display text that is sentered. for instance captions on buttons and names of players (wich needs to be directly overhead)

    I had some code for this a while ago, but i managed to delete it...

    hoping for help!

    P.S: And i use UnDelphiX and Delphi 2006.

  2. #2

    drawing sentered text?!

    If the text drawing routines use the top-left for position, then all you need to do is this.

    Calculate where you want the centre of the text to be. For a button,

    CentreX := Button.Left + (Button.Width / 2);
    CentreY := Button.Top + (Button.Height / 2);

    Calculate the width and height of the text. I don't know DelphiX, so I'm not sure what the functions would actually be.

    TextWidth := GetTextWidth(MyString);
    TextHeight := GetTextHeight(MyString);

    Now calculate where to draw the text.

    TextX := CentreX - (TextWidth / 2);
    TextY := CentreY - (TextHeight / 2);

    And draw it. Again, replace the function with what DelphiX actually uses.

    DrawText(MyString, TextX, TextY);

  3. #3

    drawing sentered text?!

    i cant see that UnDelphiX HAS a similar function as "GetTextWidth"..

    anyone using UnDelphiX here that know this?

  4. #4

    drawing sentered text?!

    Set your canvas font size and name

    then

    DXDraw1.Surface.Canvas.TextOut(100-DXDraw1.Surface.Canvas.TextWidth('test'), 10, 'test');

    Don't forget to release.
    The views expressed on this programme are bloody good ones. - Fred Dagg

  5. #5

    drawing sentered text?!

    Thanx lots!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •