鼠标悬停(类似于提示)Delphi

4

有没有事件可以确定鼠标是否悬停在编辑框上?基本上,我想为用户显示提示/帮助,但我想显示一张图片和简单的说明。最好的方法是什么?

感谢任何帮助。


1
使用自定义提示类?你不仅限于标准提示,可以制作显示任何内容的弹出式提示。 - David
3个回答

2
使用OnMouseEnterOnMouseLeave事件。在事件处理程序中,您可以设置带有提示文本的Label或类似控件的可见性。在此示例中,我使用了一个空的VCL表单,并插入了一个TEdit和一个TLabel。我实现了OnMouseMEnterOnMouseLeave事件:
  TForm1 = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    procedure Edit1MouseEnter(Sender: TObject);
    procedure Edit1MouseLeave(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Edit1MouseEnter(Sender: TObject);
begin
    Label1.Visible:=True;
end;

procedure TForm1.Edit1MouseLeave(Sender: TObject);
begin
    Label1.Visible:=False;
end;

它不起作用。当标签变为不可见时,OnEnter事件不会触发... - Stark

1
另一种解决方法可能是使用 OnMouseEnterOnMouseLeave 事件。

0

这是在Embarcadero上找到的示例:

type
  TForm1 = class(TForm)
    Button1: TButton;
    StatusBar1: TStatusBar;
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    procedure DisplayHint(Sender: TObject);
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}

{ Here is the implementation of the OnHint event handler }
{ It displays the application’s current hint in the status bar }
procedure TForm1.DisplayHint(Sender: TObject);
begin
  StatusBar1.SimpleText := GetLongHint(Application.Hint);
end;
{ Here is the form’s OnCreate event handler. }
{ It assign’s the application’s OnHint event handler at runtime }
{ because the Application is not available in the Object Inspector }
{ at design time }
procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnHint := DisplayHint;
end; 

你可以在 TLabel 的 HINT 属性上使用特殊标记,然后根据需要管理输出。

最好使用TApplicationEvents而不是直接分配给TApplication.OnHint - David Heffernan
我经常使用这个功能在状态栏中显示提示信息,"强制"用户阅读它们。 - Gabriel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接