Alinhamento no ComboBox
12/01/2008
0
Quero que valores monetários sejam apresentados no ComboBox alinhados à direita para que eu tenha virgulas embaixo de vírgulas.
Tem jeito?
Tem jeito?
Jose Almeida
Curtir tópico
+ 0
Responder
Posts
15/02/2008
Dor_poa
//ALINHAR TEXTO DO EDIT À DIREITA
procedure TForm1.Edit1Exit(Sender: TObject);
var
n: Integer;
c: TCanvas;
h: HWND;
// pode se usar Form1.Canvas se for a mesma fonte do Edit
begin
c := TCanvas.Create;
c.Handle := GetDeviceContext(h);
c.Font := Edit1.Font;
n := round((Edit1.Width - c.TextWidth(Edit1.Text) - 8) / c.TextWidth(\ ´ \´));
Edit1.Text := stringofchar(\ ´ \´, n) + Edit1.Text;
end;
procedure TForm1.Edit1Enter(Sender: TObject);
begin
Edit1.Text := Trim(Edit1.Text);
end;
OBS.: No exemplo acima e um EDIT, para combo e o mesmo!!
procedure TForm1.Edit1Exit(Sender: TObject);
var
n: Integer;
c: TCanvas;
h: HWND;
// pode se usar Form1.Canvas se for a mesma fonte do Edit
begin
c := TCanvas.Create;
c.Handle := GetDeviceContext(h);
c.Font := Edit1.Font;
n := round((Edit1.Width - c.TextWidth(Edit1.Text) - 8) / c.TextWidth(\ ´ \´));
Edit1.Text := stringofchar(\ ´ \´, n) + Edit1.Text;
end;
procedure TForm1.Edit1Enter(Sender: TObject);
begin
Edit1.Text := Trim(Edit1.Text);
end;
OBS.: No exemplo acima e um EDIT, para combo e o mesmo!!
Responder
05/07/2018
Flavio Silva
http://www.activedelphi.com.br/forum/viewtopic.php?p=10862&sid=0626aebdcde0a7f991b77c981f3ae0c5
procedure TForm1.FormCreate(Sender: TObject) ;
begin
ComboBox1.Style := csOwnerDrawFixed;
//Para ListBox use \\"lbOwnerDrawFixed\\"
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState) ;
var
x: Integer;
txt: String;
begin
with ComboBox1 do
begin
Canvas.FillRect(Rect) ;
txt := Items[Index];
x := Rect.Right - Canvas.TextWidth(txt) - 4;
Canvas.TextOut(x, Rect.Top, txt) ;
end;
end;
procedure TForm1.FormCreate(Sender: TObject) ;
begin
ComboBox1.Style := csOwnerDrawFixed;
//Para ListBox use \\"lbOwnerDrawFixed\\"
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState) ;
var
x: Integer;
txt: String;
begin
with ComboBox1 do
begin
Canvas.FillRect(Rect) ;
txt := Items[Index];
x := Rect.Right - Canvas.TextWidth(txt) - 4;
Canvas.TextOut(x, Rect.Top, txt) ;
end;
end;
Responder
Clique aqui para fazer login e interagir na Comunidade :)