Fórum centralizar texto #163138

28/05/2003

0

Pessoal como centralizar um texto no Edit ou MaskEdit ou no DbEdit no Delphi 5 ..

Abraços.


Fabiano




______________________
[color=blue:90b7462340][b:90b7462340]CRÊ NO SENHOR JESUS CRISTO E SERAS SALVO TU E TUA CASA[/b:90b7462340][/color:90b7462340]


Fabianosouza

Fabianosouza

Responder

Posts

28/05/2003

Jycn

Veja se isto te serve, esta dica foi tirada de www.mundodelphi.com.br.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function AlinharStr(Pe_Str:string; Pe_QtdPos:Byte; EDC :Char):string;
var
Form1: TForm1;

implementation

{$R *.dfm}

function AlinharStr(Pe_Str:string; Pe_QtdPos:Byte; EDC :Char):string;
// EDC: C = Centralizado
// D = Direita
// E = Esquerda
var
L, N, R, I :integer;
S, St, CH :string;
begin
i := Pe_qtdPos;
St := copy(Pe_Str,1,Pe_QtdPos);
if EDC = ´D´ then
begin
Insert(´aLeX´,St,i);
L := Pos(´aLeX´,St);
if L <= i then
begin
for n := L to i do
begin
Insert(´ ´, St, 1);
end;
end;
St := Copy(St,1,i);
R := i;
Ch := Copy(St,i,1);
while (Ch = ´ ´) and (R <> 0) do
begin
if ch = ´ ´ then
begin
Insert(´ ´, St, 1);
end;
St := Copy(St, 1, i);
R := R - 1;
Ch := Copy(St, i, 1);
end;
end;
if EDC = ´E´ then
begin
Ch := Copy(St,1,1);
while Ch = ´ ´ do
begin
Delete(St,1,1);
Ch := Copy(St,1,1);
end;
St := Copy(St,1,i);
end;
if EDC = ´C´ then
begin
S := AlinharStr(Pe_Str,Pe_QtdPos,´D´);
Ch := Copy(S,1,1);
R := 1;
N := 1;
while Ch = ´ ´ do
begin
R := R + 1;
Ch := Copy(S,R,1);
end;
R := Round( R / 2 );
while n < R do
begin
Delete(S,1,1);
N := N + 1;
end;
St := Copy(S,1,i);
end;
AlinharStr := St;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
Edit2.Text:=AlinharStr(Edit1.Text,20,´C´);
end;

end.


Jycn


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar