Solved

How to tell when the mouse has moved outside the bounds of a Control

Posted on 2001-09-12
4
193 Views
Last Modified: 2010-04-06
Hi All,
I've been trying to write a small program that uses a THintWindow to show a hint when the mouse is over a ListBox.  I already have the code for showing the hint when the mouse is over the ListBox but I am having problem with clearing the hint once the mouse moves outside the Listbox.  When the hint is displayed, I start a timer and when the OnTimer event is fired, I call the THintWindow.ReleaseHandle which clears the hint for me.

I can hear you all asking, but why am I not using the Application Hint?  Well, the Application Hint calls GetShortHint() which breaks up the hint when it reaches a binary OR symbol "|" and seeing how I want to display this symbol in the hint, I can't use the Applications Hint.  By displaying the Hint using a THintWindow, I can display anything I want.

Now, back to my problem.  Is there a way of determining when the mouse moves outside the bounds of the ListBox?  If I can work out when the mouse has moved outside the bounds, then I can call THintWindow.ReleaseHandle to clear the hint.

If anyone can think of a better way of displaying the hint then please let me know.

Thanks.
0
Comment
Question by:MMathieson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6477769
Write the THintWindow.ReleaseHandle when the mouse move event of the form, or any component if it's contain the listbox (like panel)
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 100 total points
ID: 6477836
You could do something like this:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TMyListBox = class(TListBox)
  private
    { Private declarations }
    MouseOverListBox : Boolean;
    procedure CMMouseEnter(var Msg : TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Msg : TMessage); message CM_MOUSELEAVE;
  end;

var
  Form1: TForm1;
  ListBox : TListBox;

implementation

{$R *.DFM}
procedure TMyListBox.CMMouseEnter(var Msg : TMessage);
begin
  MouseOverListBox := True
end;

procedure TMyListBox.CMMouseLeave(var Msg : TMessage);
begin
  if MouseOverListBox = True then
  begin
    MouseOverListBox := False;
    THintWindow.ReleaseHandle;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ListBox := TMyListBox.Create(self);
  with ListBox do
  begin
    Parent := Form1;
    Left := 100;
    Top := 100;
    Items.Add('Test');
  end;
end;

end.

Cheers,

Alan
0
 

Author Comment

by:MMathieson
ID: 6477851
I thought of that but I was hoping to be able to get away without writing extra code for other events.  i.e. I would only need to put code in the ListBox.MouseMove event to show the hint.
0
 

Author Comment

by:MMathieson
ID: 6477936
Thanks Alan,
That's going to work well although I did get around my problem by using another timer.  When the second OnTimer event fired, I checked if the mouse was still over the ListBox.  If it wasn't, then I called THintWindow.ReleaseHandle
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reconfigure Delphi Install? 2 65
Controlled Assessment GCSE - desperate help needed 4 111
JAudiorecorder record freezing the app 29 82
Delphi Seattle StructureView color 1 21
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question