CSDN博客

img programlover

OICQ中用户图标选择的实现

发表于2000/12/13 11:19:00  527人阅读

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.

阅读全文
0 0

相关文章推荐

img
取 消
img