OICQ中用户图标选择的实现

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
                 var
s: String;
begin
 Randomize;
 s:= intTostr(Random(100));//LAST HERE!
 CreateDir(s);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
Bit1,Bit2,Bit3,Bit4,Bit5,Bit6: TBitmap;
begin
  List1.Style := csOwnerDrawVariable;
  List1.ItemHeight := 30;
  Bit1 := TBitmap.Create;
  Bit1.LoadFromFile('C:/Program Files/Oicq/face/1-1.bmp');
  Bit2 := TBitmap.Create;
  Bit2.LoadFromFile('C:/Program Files/Oicq/face/2-1.bmp');
  Bit3 := TBitmap.Create;
  Bit3.LoadFromFile('C:/Program Files/Oicq/face/3-1.bmp');
  Bit4 := TBitmap.Create;
  Bit4.LoadFromFile('C:/Program Files/Oicq/face/4-1.bmp');
  Bit5 := TBitmap.Create;
  Bit5.LoadFromFile('C:/Program Files/Oicq/face/5-1.bmp');
  Bit6 := TBitmap.Create;
  Bit6.LoadFromFile('C:/Program Files/Oicq/face/6-1.bmp');
  List1.Items.AddObject('图标1',Bit1);
  List1.Items.AddObject('图标2',Bit2);
  List1.Items.AddObject('图标3', Bit3);
  List1.Items.AddObject('图标4', Bit4);
  List1.Items.AddObject('图标5', Bit5);
  List1.Items.AddObject('图标6', Bit6);
  List1.ItemIndex :=0;
end;

procedure TForm1.List1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
Bitmap: TBitmap;
Offset: Integer;
begin
  with(Control as TCombobox).Canvas do
  begin
    FillRect(Rect);
    Bitmap := TBitmap(List1.Items.Objects[Index]);
    //Bitmap := TBitmap.Create;
    //ImageList1.GetBitmap(Index,Bitmap);
    if Bitmap<> Nil then
    begin
      BrushCopy(Bounds(Rect.Left+2,Rect.Top+2,Bitmap.Width,Bitmap.Height),Bitmap,
              Bounds(0,0,Bitmap.Width,Bitmap.Height),clRed);
    Offset := Bitmap.Width + 8;
    TextOut(Rect.Left+OffSet,Rect.Top,List1.Items[Index]);
    end;

  end;


end;

end.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

programlover

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值