OICQ中使用者圖示選擇的實現 (轉)

worldblog發表於2007-12-02
OICQ中使用者圖示選擇的實現 (轉)[@more@]

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
  List1: TComboBox;
  Button1: TButton;
  procedure Button1Click(Sender: T);
  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
 Ranize;
 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 FilesOicqface1-1.bmp');
  Bit2 := TBitmap.Create;
  Bit2.LoadFromFile('C:Program FilesOicqface2-1.bmp');
  Bit3 := TBitmap.Create;
  Bit3.LoadFromFile('C:Program FilesOicqface3-1.bmp');
  Bit4 := TBitmap.Create;
  Bit4.LoadFromFile('C:Program FilesOicqface4-1.bmp');
  Bit5 := TBitmap.Create;
  Bit5.LoadFromFile('C:Program FilesOicqface5-1.bmp');
  Bit6 := TBitmap.Create;
  Bit6.LoadFromFile('C:Program FilesOicqface6-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.


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-987429/,如需轉載,請註明出處,否則將追究法律責任。

相關文章