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

Texto Justificado, Como?


demetriusgs

Pergunta

10 respostass a esta questão

Posts Recomendados

  • 0

O que o amigo quer se for justificar um memo ate hoje não achei nenhum componente que faça isso, pelo menos free. Tem uma funçao que testei aqui no meu sistema, justifica, mais infelizmente não como deveria justificar igualzinho a do word

function Justifica(mCad:string;mMAx:integer):string;

var

mPos,mPont,mTam,mNr,mCont:integer;

mStr:string;

begin

mTam:=Length(mCad);

if mTam>=mMax then

Result:=copy(mCad,1,mMax)

else

mStr:='';

mCont:=0;

mPont:=1;

mNr:=mMax-mTam;

while mCont<mNr do

begin

mPos:=pos(mStr,copy(mCad,mPont,100));

if mPos=0 then

begin

mStr:=mStr+' ';

mPont:=1;

continue;

end

else

begin

mCont:=mCont+1;

Insert(' ',mCad,mPos+mPont);

mPont:=mPont+mPos+length(mStr);

end;

Result:=mCad;

end;

end;

falou

T+

Link para o comentário
Compartilhar em outros sites

  • 0
O que o amigo quer se for justificar um memo ate hoje não achei nenhum componente que faça isso, pelo menos free. Tem uma funçao que testei aqui no meu sistema, justifica, mais infelizmente não como deveria justificar igualzinho a do word

function Justifica(mCad:string;mMAx:integer):string;

var

mPos,mPont,mTam,mNr,mCont:integer;

mStr:string;

begin

mTam:=Length(mCad);

if mTam>=mMax then

Result:=copy(mCad,1,mMax)

else

mStr:='';

mCont:=0;

mPont:=1;

mNr:=mMax-mTam;

while mCont<mNr do

begin

mPos:=pos(mStr,copy(mCad,mPont,100));

if mPos=0 then

begin

mStr:=mStr+' ';

mPont:=1;

continue;

end

else

begin

mCont:=mCont+1;

Insert(' ',mCad,mPos+mPont);

mPont:=mPont+mPos+length(mStr);

end;

Result:=mCad;

end;

end;

falou

T+

Desculpe o incomodo mas é que sou iniciante.

E depois como eu faria para usar a função justifica?

Link para o comentário
Compartilhar em outros sites

  • 0

E depois como eu faria para usar a função justifica?

Ola amigo essa funçao é horrivel porque ele deixa o texto do memo todinho justificado ai sobra espaços enormes entre as palavras, Exemplo: sou programador Delphi

Entendeu, mais se quiser testar use um bitbtn e inclua esse codigo

Justifica(mmemo1.LINES, memo1.font, memo1.width);

Link para o comentário
Compartilhar em outros sites

  • 0

Tenta essa:

procedure Justify;
const
WM_USER = $400;
EM_EXSETSEL = (WM_USER + 55);
EM_SETTYPOGRAPHYOPTIONS = (WM_USER + 202);
EM_GETTYPOGRAPHYOPTIONS = (WM_USER + 203);
TO_ADVANCEDTYPOGRAPHY = $1;
mZERO = $0;
var x :tparaformat;
L :LongInt;
cp :charrange;
begin
x.cbSize := sizeof(x);
if Form1.RichEdit1.SelLength = 0 then
    begin
    cp.cpMin := 0;
    cp.cpMax := length(Form1.RichEdit1.Text);
    SendMessage(Form1.RichEdit1.Handle,EM_EXSETSEL,mZERO,LPARAM(@cp));
    end;
L := SendMessageA(Form1.RichEdit1.Handle,EM_SETTYPOGRAPHYOPTIONS, TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY);
    if L = 1 then
    begin
    SendMessageA(Form1.RichEdit1.Handle, EM_GETTYPOGRAPHYOPTIONS, mZERO, mZERO);
    SendMessage(Form1.RichEdit1.Handle, EM_GETPARAFORMAT, mZERO, LPARAM(@x));
    x.dwMask := PFM_ALIGNMENT;
    x.wAlignment := PFA_JUSTIFY;
    SendMessage(Form1.RichEdit1.Handle, EM_SETPARAFORMAT, mZERO, lparam(@x));
    end;
cp.cpMin := 0;
cp.cpMax := 0;
SendMessage(Form1.RichEdit1.Handle,EM_EXSETSEL,mZERO,lparam(@cp));
Form1.RichEdit1.WordWrap := true;
end;
ai é so chamar assim:
Justify;

Abraços!

Link para o comentário
Compartilhar em outros sites

  • 0

Bastard2003...

Estou tentando usar essa função no delphi 7 mas, não esta reconhecendo os tipos TParaFormat e CharRange.

Está faltando alguma biblioteca ou algo assim?

Se puder responde eu agradeço.

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
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...