Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create Database on Android via Delphi dbExpress 3 143
Working with hours 3 88
Firemonkey allowing RTL on android 6 77
Delphi: sending SMS on android platform 1 104
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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