delphi combobox和listbox的文字可以右对齐显示


本文整理自网络,侵删。

 

combobox和listbox的文字可以右对齐显示么?答案是可以的,但是必须使用ComboBox1DrawItem,自行画内容。

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  ComboBox1.Style := csOwnerDrawFixed;
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); //将combobox用现在的brush填充颜色
    txt := Items[Index];
    x := Rect.Right - Canvas.TextWidth(txt) - 4;
    Canvas.TextOut(x, Rect.Top, txt);
  end;
end;

end.

相关阅读 >>

Delphi 限制窗体大小的最大值与最小值

Delphi tclientdataset的使用

Delphi中判断webbrowser的页面是否加载完成

Delphi twebbrowser 响应回车键(ewb响应正常,无需额外代码)

Delphi 简单播放mp3

Delphi float转换int

Delphi 使用 idhttp 获取 utf-8 编码的中文网页

Delphi : tstringlist的find,indexof和sort

Delphi fastreport快速安装教程

Delphi让文本框接受文件拖放

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...