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

时间:2014-10-21 09:33:15

标签: delphi delphi-xe6

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

感谢您的帮助

3 个答案:

答案 0 :(得分:2)

使用OnMouseEnterOnMouseLeave事件。在事件处理程序中,您可以使用提示文本设置Label或simliar控件的可见性。在示例中,我使用了一个空的VCL表单并插入了TEditTLabel。我实施了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;

答案 1 :(得分:1)

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

答案 2 :(得分: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属性上使用特殊标记,然后根据需要管理输出。