Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 150
  • Last Modified:

Special Button!

I want to create a button which will change when the user place the mouse cursor over it(just like buttons in netscape and internet explorer).I can use the OnMouseMove event to do this. But how to change the button back to the original one when the user moves the mouse cursor away? I've tried to use  the OnMouseMove event of the form. But I found that if the button is very close to the border, the user can move the mouse away very quickly and the button will not change to the original one. This will also happen when that button is very close to another component(it is a TMemo) and the user move the mouse cursor to it very quickly. The buttons in IE and netscape communicator cannot be cheated by this method. How to do this?
0
sccheung
Asked:
sccheung
  • 2
  • 2
1 Solution
 
sperlingCommented:
When the mouse cursor first enters your button, call SetCapture. This'll give you all mouse messages regardless of where the cursor is located. As soon as the cursor is outside the bounds of your button, call ReleaseCapture to restore normal processing of mouse messages.

Regards,

Erik.

0
 
StevenBCommented:
 I don't want to malign anyone elses answer, but there is, I believe, a better solution using the messages:

  message CM_MouseEnter;
  message CM_MouseLeave;

  If you use these messages (which admittedly are not well documented in delphi) then you can get very precise and neat control over the movement of the Mouse into and out of your component.

  Steven.


0
 
sccheungAuthor Commented:
Steven,
   I have tried Erik's solution and it works. After that, I want to try your solution but I cannot find the badly documented help. I can only find a list of component message which contains the messages you mentioned. I learn Delphi only 2 months ago and I do not know how  to use message. I and still saving up money to buy an advanced Delphi book. Can I know these advanced skills in advance? I am only a 15-year-old boy with very little pocket money. It will take me a very long time to save up enough money to buy that book.
0
 
StevenBCommented:
 Infact there is NO help on these messages, rather than bad help. If you'd like some example code for a button which does what you're trying to do then I'd be more than happy to mail it to you. I wrote this button a while ago and it's pretty simple to understand. If you'd like the code then mail me at :
stemail@dial.pipex.com

  'Cause I can't keep paying 10 points to continue this here.

  Steven.
0
 
sperlingCommented:
Steven's solution is in fact better and more correct than mine. The reason I didn't mention these messages were simply that they require more knowledge of Delphi than you seem to have, to be successfully implemented. The main problem is that these messages would require you to create a new component, whereas the SetCapture method allows you to drop a button on a form and work with the available events.

When you've used Delphi for a while, I'd suggest you use these messages to implement your own custom button that you could drop on any form, that would be a nice excercise in message handling and event creation.

Regards,

Erik.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now