Search code examples
delphidelphi-xe6

Mouse hovering(similar to hint) delphi


Is there any event that determines, if the mouse is hovering above an edit box? Basically, I want to show a hint/help for the user, but I want to display an image and simple instructions. What would be the best way to proceed?

Thanks for any help


Solution

  • Use the OnMouseEnter and OnMouseLeave events. In the event handlers, you can set the visibility of a Label or simliar control with the hint text. In the example, I took an empty VCL form and inserted a TEdit and a TLabel. I implemented the OnMouseMEnter and the OnMouseLeave events:

      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;