Canvas auto centre names - Programmers Heaven

Howdy, Stranger!

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

Categories

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.