【问题标题】:Mouse hovering(similar to hint) delphi鼠标悬停(类似于提示)delphi
【发布时间】:2014-12-16 11:36:24
【问题描述】:

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

感谢您的帮助

【问题讨论】:

  • 使用自定义提示类?您不仅限于标准提示,还可以制作显示任何内容的弹出提示。

标签: delphi delphi-xe6


【解决方案1】:

这是在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
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    使用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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 2011-08-04
      • 2018-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多