Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) Componente Memo Com Texto Justificado


Guest carlinhosprog

Pergunta

1 resposta a esta questão

Posts Recomendados

  • 0

Função para alinhar texto em um memo

function StrPad(AValue: String; const ALength: Integer; const ASide: TAlignment): String;
begin
   AValue := Trim(AValue);
   if Length(AValue) > ALength then
      AValue := Copy(AValue,1,ALength);
   case ASide of
      taLeftJustify:
         while Length(AValue) < ALength do AValue := AValue + ' ';
      taRightJustify:
         while Length(AValue) < ALength do AValue := ' ' + AValue;
      taCenter:
         while Length(AValue) < ALength do if (Length(AValue) mod 2)= 0 then
            AValue := AValue + ' ' else AValue := ' ' + AValue;
   end;
   Result := AValue;
end;


// tamanho da linha = 80 caracteres 

procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
   showmessage(inttostr(MEMO1.LINES.Count));
   for i := 1 to MEMO1.LINES.Count do
      begin
         if Length(MEMO1.LINES.Strings[i]) < 80 then 
            MEMO2.LINES.Append(StrPad(MEMO1.LINES.Strings[i],80,TACENTER))
         else
            begin
               MEMO2.LINES.Append(StrPad(MEMO1.LINES.Strings[i],80,TACENTER));
               MEMO2.LINES.Append(StrPad(copy(MEMO1.LINES.Strings[i],81,80),80,taLeftJustify));
            end;
      end;

end;

OBS: a fonte a ser utilizada deve ser a Courier ou Courier New ( os caracteres tem espaçamentos iguais )

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152k
    • Posts
      651,7k
×
×
  • Criar Novo...