Is it possible to leave the label and text at 90 degrees?

Asked

Viewed 1,162 times

5

It is possible to make a TLabel stand upright, but your text like this:

inserir a descrição da imagem aqui

I have tested some components, but they do not work in the version of Delphi-XE8.

I managed to let him in 90 degrees but the numbers come out underneath each other

Any idea?

2 answers

4

You cannot rotate the component TLabel (as far as I have discovered), you can find components around that support this behavior, the Firemonkey is able to generate this effect!

However, it follows a procedure that can clarify your ideas and maybe get where you want!

Implement this in the OnPaint form!

var
  lf: TLogFont;
  tf: TFont;
begin
  with Form1.Canvas do
  begin
    Font.Name := 'Arial';
    Font.Size := 24;
    tf        := TFont.Create;
    try
      tf.Assign(Font);
      GetObject(tf.Handle, SizeOf(lf), @lf);
      lf.lfEscapement  := 320;
      lf.lfOrientation := 320;
      SetBkMode(Handle, TRANSPARENT);
      tf.Handle := CreateFontIndirect(lf);
      Font.Assign(tf);
    finally
      tf.Free;
    end;
    TextOut(10, Height div 2, 'Texto Rotacionado aqui!');
  end;

Take a look at the Firemonkey, you can find something that I can help even more!

If not solved, you can copy the String and generate an image in (TImage), rotate and position at the location of the TLabel.

Following question and answer of how to convert String to Image:

Right here in Sobr

1


I got it this way. Add text to an image like @Júnior’s idea

with the code below.

procedure TForm2.ConvTextOut(CV: TCanvas; const sText: String; x, y,
  angle: integer);
var
  LogFont: TLogFont;
  SaveFont: TFont;
begin
  SaveFont := TFont.Create;
  SaveFont.Assign(CV.Font);
  GetObject(SaveFont.Handle, sizeof(TLogFont), @LogFont);
  with LogFont do
  begin
    lfEscapement := angle *10;
    lfPitchAndFamily := FIXED_PITCH or FF_DONTCARE;
  end;
  CV.Font.Handle := CreateFontIndirect(LogFont);
  SetBkMode(CV.Handle, TRANSPARENT);
  CV.TextOut(x, y, sText);
  CV.Font.Assign(SaveFont);
  SaveFont.Free;
end;

ConvTextOut(Origem.Canvas, label1.caption, 0, 0, 0);
  Resultado.Width := Origem.Height;
  Resultado.Height := Origem.Width;
  Resultado.Update;
  for k := 0 to Origem.Width do
    for Y := 0 to Origem.Height do
      Resultado.Canvas.Pixels[Origem.Height-Y, k] := Origem.Canvas.Pixels[k,Y];

The only thing that was not 100% in my view was that the size of the caption inside the image was not a cool size.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.