P
pjx1017
Unregistered / Unconfirmed
GUEST, unregistred user!
窗体上的组件有:Tabset,filelistbox,3个image。其中Tabset的style设为tsOwnerDraw。3个image中各放入一个位图。
问题:1、运行都能通过,但为什么在Tabset上不能显示位图。是不是procedure TForm1.drivetabsetDrawTab没有被执行。
2、用addobject将字符串与图像关联了之后,如何显示出图像来。能给一个简单的例子最好。
急用!先谢谢各位了。
程序代码如下:
unit Uaddobject1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Tabs, ExtCtrls, StdCtrls, FileCtrl, Grids, Outline, Buttons;
type
TForm1 = class(TForm)
drivetabset: TTabSet;
floppy: TImage;
fixed: TImage;
network: TImage;
FileListBox1: TFileListBox;
procedure drivetabsetMeasureTab(Sender: TObject; Index: Integer;
var TabWidth: Integer);
procedure FormCreate(Sender: TObject);
procedure drivetabsetDrawTab(Sender: TObject; TabCanvas: TCanvas;
R: TRect; Index: Integer; Selected: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.drivetabsetMeasureTab(Sender: TObject; Index: Integer;
var TabWidth: Integer);
var
BitmapWidth: Integer;
begin
BitmapWidth := TBitmap(DriveTabSet.Tabs.Objects[Index]).Width;
Inc(TabWidth, 2 + BitmapWidth);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
drive:char;
addedindex:integer;
begin
for drive:='a' to 'z' do
begin
case Getdrivetype(pchar(drive+':/')) of //[green]在这条语句中pchar()这种表示是进行强制性转换吗?[/green]
drive_removable:
addedindex:=drivetabset.Tabs.AddObject(drive,floppy.picture.graphic);
DRIVE_FIXED:
AddedIndex := DriveTabSet.Tabs.AddObject(Drive, Fixed.Picture.Graphic);
DRIVE_REMOTE:
AddedIndex := DriveTabSet.Tabs.AddObject(Drive, Network.Picture.Graphic);
end;
if UpCase(Drive) = UpCase(filelistbox1.Drive) then
DriveTabSet.TAbIndex := AddedIndex;
end;
end;
procedure TForm1.drivetabsetDrawTab(Sender: TObject; TabCanvas: TCanvas;
R: TRect; Index: Integer; Selected: Boolean);
var
Bitmap: TBitmap;
begin
Bitmap := TBitmap(DriveTabSet.Tabs.Objects[Index]);
with TabCanvas do
begin
Draw(R.Left, R.Top + 4, Bitmap);
TextOut(R.Left + 2 + Bitmap.Width, R.Top + 2, DriveTabSet.Tabs[Index]);
end;
end;
end.
问题:1、运行都能通过,但为什么在Tabset上不能显示位图。是不是procedure TForm1.drivetabsetDrawTab没有被执行。
2、用addobject将字符串与图像关联了之后,如何显示出图像来。能给一个简单的例子最好。
急用!先谢谢各位了。
程序代码如下:
unit Uaddobject1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Tabs, ExtCtrls, StdCtrls, FileCtrl, Grids, Outline, Buttons;
type
TForm1 = class(TForm)
drivetabset: TTabSet;
floppy: TImage;
fixed: TImage;
network: TImage;
FileListBox1: TFileListBox;
procedure drivetabsetMeasureTab(Sender: TObject; Index: Integer;
var TabWidth: Integer);
procedure FormCreate(Sender: TObject);
procedure drivetabsetDrawTab(Sender: TObject; TabCanvas: TCanvas;
R: TRect; Index: Integer; Selected: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.drivetabsetMeasureTab(Sender: TObject; Index: Integer;
var TabWidth: Integer);
var
BitmapWidth: Integer;
begin
BitmapWidth := TBitmap(DriveTabSet.Tabs.Objects[Index]).Width;
Inc(TabWidth, 2 + BitmapWidth);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
drive:char;
addedindex:integer;
begin
for drive:='a' to 'z' do
begin
case Getdrivetype(pchar(drive+':/')) of //[green]在这条语句中pchar()这种表示是进行强制性转换吗?[/green]
drive_removable:
addedindex:=drivetabset.Tabs.AddObject(drive,floppy.picture.graphic);
DRIVE_FIXED:
AddedIndex := DriveTabSet.Tabs.AddObject(Drive, Fixed.Picture.Graphic);
DRIVE_REMOTE:
AddedIndex := DriveTabSet.Tabs.AddObject(Drive, Network.Picture.Graphic);
end;
if UpCase(Drive) = UpCase(filelistbox1.Drive) then
DriveTabSet.TAbIndex := AddedIndex;
end;
end;
procedure TForm1.drivetabsetDrawTab(Sender: TObject; TabCanvas: TCanvas;
R: TRect; Index: Integer; Selected: Boolean);
var
Bitmap: TBitmap;
begin
Bitmap := TBitmap(DriveTabSet.Tabs.Objects[Index]);
with TabCanvas do
begin
Draw(R.Left, R.Top + 4, Bitmap);
TextOut(R.Left + 2 + Bitmap.Width, R.Top + 2, DriveTabSet.Tabs[Index]);
end;
end;
end.