Solved

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

Posted on 2001-09-12
4
183 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
  • 2
4 Comments
 
LVL 22

Expert Comment

by:mnasman
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now