FileListBox问题请教(20分)

  • 主题发起人 主题发起人 Ming618
  • 开始时间 开始时间
M

Ming618

Unregistered / Unconfirmed
GUEST, unregistred user!
文件名的长度超过FileListBox的长度,请
问如何把FileListBox的Hint设置为鼠标
当前所指向的文件,并显示出来?
 
请高的指点!
 
FileListBox1.Hint:=FileListbox1.FileName;

注意将form.showhint:=true;
 
此方法好象不行,我想要的效果是:鼠标每指一个文件,就改变Hint并显示出来
 
请高手指点呀!
 
FileListBox1.ShowHint := true;

procedure TForm1.FileListBox1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var i:integer;
begin
i:=y div FileListBox1.ItemHeight;
if i<FileListBox1.items.count then FileListBox1.Hint := FileListBox1.Items;
end;
 
让俺试试,成功立即送分
 
好象不行,鼠标第一次指向一个文件时可以,但移动后指向其它文件Hint却不变
 
unit Unit1;

interface

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

type
TForm1 = class(TForm)
FileListBox1: TFileListBox;
Button1: TButton;
procedure FileListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);

private
{ Private declarations }

public
{ Public declarations }

end;

var
Form1: TForm1;
hw:THintWindow;

implementation

{$R *.DFM}

procedure TForm1.FileListBox1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var i:integer;
po: TPoint;
p :Pointer;
rect :TRect;
begin

po := ClientToScreen(Point(X, Y));
po.x := FileListBox1.Left+po.x;
po.y := FileListBox1.Top+po.y;

i:=y div FileListBox1.ItemHeight;
if (i<FileListBox1.items.count) then
begin
//FileListBox1.Hint := FileListBox1.Items;
rect := hw.CalcHintRect(po.x+200,FileListBox1.hint,p);
rect.Left := po.x+10;
rect.Right := po.x+length(FileListBox1.Items)*FileListBox1.Font.Size;
rect.Top := po.y;
rect.Bottom := po.y+FileListBox1.ItemHeight;
hw.Color := clInfoBk;
hw.ActivateHint(rect,FileListBox1.Items);
end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FileListBox1.ShowHint := false;
hw := THintWindow.Create(self);
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var rect :TRect;
p: pointer;
begin
rect := hw.CalcHintRect(0,FileListBox1.hint,p);
hw.ActivateHint(rect,'');
end;

end.
 
多人接受答案了。
 
后退
顶部