Solved

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

Posted on 2001-09-12
4
186 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: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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

20 Experts available now in Live!

Get 1:1 Help Now