We help IT Professionals succeed at work.

Using OnEnter and OnExit to control cursor

John Fistere
John Fistere asked
on
1,160 Views
Last Modified: 2010-08-05
I have a form with a hyperlink to a web page and that works just fine.  I want to change the cursor to a pointing hand when the cursor is over the hyperlink text.  I originally had a simple label and the OnClick worked just fine for the hyperlink but there was no OnEnter/Exit for the label to control the cursor.

So I put the text in a tight-fitting panel which does have those events.  The code for those events is:

procedure TfrmMainForm.Panel1Enter(Sender: TObject);
begin
  Screen.Cursor := crHandPoint;
end;

procedure TfrmMainForm.Panel1Exit(Sender: TObject);
begin
  Screen.Cursor := crDefault;
end;

The problem is that when I move the cursor over the panel, the OnEnter routiine is not triggered and the cursor stays the same.

What do I need to do to trigger both of the routines?

Thanks,
John Fistere
Comment
Watch Question

John FistereEngineer, retired

Author

Commented:
Never mind!

As is often the case, once I ask the question, I figure out the answer.  It's true in many areas of life.  One of the best ways to find something is to buy a replacement.

Anyway, I found I don't need OnEnter/Exit.  All I had to do was set the Cursor property of the panel to crHandPoint.  It works just fine.

I am still surprised that the program would not enter the OnEnter routine, though.

Cheers,
John Fistere
Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Commented:
[quote] I want to change the cursor to a pointing hand when the cursor is over the hyperlink text[/quote]

It might serve you to look at this article I posted...
http://www.delphipages.com/news/detaildocs.cfm?ID=147

John FistereEngineer, retired

Author

Commented:
Thanks, Ed,

I saw your article when I was first starting out.  It seemed a little complicated to me.  I ultimately found the following code in the D5 help system:

procedure TfrmMainForm.lbHyperlinkClick(Sender: TObject);

var
  HTML_File: string;
begin
  HTML_File := 'http://www.<------------------->';
  ShellExecute(Handle, 'open', PChar(HTML_File),    
   nil, nil, SW_SHOW);
end;

What wasn't clear initially was that I had to add ShellApi to the uses statement.  It seems to work fine.  Does your solution do something else special?

John Fistere
John FistereEngineer, retired

Author

Commented:
Regarding the issue of making the hand pointer appear, I found that all I had to do was set the Cursor property of the text label itself to crHandPoint.  No panel or event routines were required.

John Fistere
Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Commented:
No, it just changes the appearance of the TStaticText labels when the mouse is over it and handles a click to open
a url when clicked... see StaticText1Click.

Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Commented:
No objections.

JFistere,
The OnEnter/OnExit for the panel only occurs when a control contained in the panel or the panel itself RECEIVES FOCUS.
To get an OnMouseEnter/OnMouseLeave solution, you have to follow the solution I proposed. This would allow you
to also change the font color/style when the cursor is over the label which you cannot do by just setting the cursor
property of the label.
John FistereEngineer, retired

Author

Commented:
Thanks Eddie.

Since all I wanted to do was create the pointer on Mouse Over and I found a simple way to do that, I didn't award points.  I hope you really feel that is OK.

Thanks for the info on OnEnter/OnExit and your routines.

John
Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Commented:
Well, it's just that that is not what you asked to begin with.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.