Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Canvas auto centre names

I been trying to auto centre the names in my box around name because not all names are not the same size can anyone help me fix this so it centres all names?

[code]

PaintInfo.Canvas.Pen.Color:= clAqua;
PaintInfo.Canvas.Rectangle(n+20,0,n+20+PaintInfo.Canvas.TextWidth(s)+119,
PaintInfo.Canvas.TextHeight(IMData.Name)+2);
PaintInfo.Canvas.Font.Color := clAqua; // Account Color
PaintInfo.Canvas.Draw(n, t, ResForm.repc.Picture.Bitmap);
n := n + 15; // Account Icon
PaintInfo.Canvas.TextOut(n+45,1,IMData.Name); // Screen Name

[/code]

cheers and thank you

Slewis

Comments

  • zibadianzibadian Posts: 6,349Member
    : I been trying to auto centre the names in my box around name because not all names are not the same size can anyone help me fix this so it centres all names?
    :
    : [code]
    :
    : PaintInfo.Canvas.Pen.Color:= clAqua;
    : PaintInfo.Canvas.Rectangle(n+20,0,n+20+PaintInfo.Canvas.TextWidth(s)+119,
    : PaintInfo.Canvas.TextHeight(IMData.Name)+2);
    : PaintInfo.Canvas.Font.Color := clAqua; // Account Color
    : PaintInfo.Canvas.Draw(n, t, ResForm.repc.Picture.Bitmap);
    : n := n + 15; // Account Icon
    : PaintInfo.Canvas.TextOut(n+45,1,IMData.Name); // Screen Name
    :
    : [/code]
    :
    : cheers and thank you
    :
    : Slewis
    :
    The calculation for centering something is quite simple:
    [code]
    x := (CanvasWidth - TextWidth) div 2;
    [/code]
    where CanvasWidth is the width of the area in which the text appears, and TextWidth is the width of the text; both in pixels. X forms the left hand coordinate of the text.
  • DevelopmentDevelopment Posts: 222Member
    : : I been trying to auto centre the names in my box around name because not all names are not the same size can anyone help me fix this so it centres all names?
    : :
    : : [code]
    : :
    : : PaintInfo.Canvas.Pen.Color:= clAqua;
    : : PaintInfo.Canvas.Rectangle(n+20,0,n+20+PaintInfo.Canvas.TextWidth(s)+119,
    : : PaintInfo.Canvas.TextHeight(IMData.Name)+2);
    : : PaintInfo.Canvas.Font.Color := clAqua; // Account Color
    : : PaintInfo.Canvas.Draw(n, t, ResForm.repc.Picture.Bitmap);
    : : n := n + 15; // Account Icon
    : : PaintInfo.Canvas.TextOut(n+45,1,IMData.Name); // Screen Name
    : :
    : : [/code]
    : :
    : : cheers and thank you
    : :
    : : Slewis
    : :
    : The calculation for centering something is quite simple:
    : [code]
    : x := (CanvasWidth - TextWidth) div 2;
    : [/code]
    : where CanvasWidth is the width of the area in which the text appears, and TextWidth is the width of the text; both in pixels. X forms the left hand coordinate of the text.
    :
    hi zib would it be possable for you to redo my code for me ?
    Slewis

Sign In or Register to comment.