keithcsl
asked on
OnMoveMove Event
Hi
My problem is quite straight forward. I have got 2 edit boxes. if the mouse is over edit1, then it will make edit2 go RED, else it will make edit2 go WHITE.
I have used the OnMouseMove event of edit1 and make edit2 RED. All OK. then, I have used the OnMouseMove event of the form to set the edit2 to WHITE. All OK
Now, if i place edit1, close to the edge of the form, and move my mouse fast enough out of the form, edit2 remains RED, because the move movement was to fast to go through the OnMouseMove event of the form.
How do i overcome this? any better ideas anyone?
Regards
Keith
My problem is quite straight forward. I have got 2 edit boxes. if the mouse is over edit1, then it will make edit2 go RED, else it will make edit2 go WHITE.
I have used the OnMouseMove event of edit1 and make edit2 RED. All OK. then, I have used the OnMouseMove event of the form to set the edit2 to WHITE. All OK
Now, if i place edit1, close to the edge of the form, and move my mouse fast enough out of the form, edit2 remains RED, because the move movement was to fast to go through the OnMouseMove event of the form.
How do i overcome this? any better ideas anyone?
Regards
Keith
Yes, there is a better method. There are events called CM_MOUSEENTER and CM_MOUSELEAVE. They aren't implemented in all controls, but we can make a "remix" of the edit, and use it insted. If I don't come back in 10 minutes, DIY ;-)
Hi keithcsl,
a very easy solution is :
procedure TForm1.Edit1MouseMove(Send er: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (X = 0) or (X=(Sender as TEdit).width) or
(Y=0) or (Y=(Sender as TEdit).Height) then edit2.Color := clWhite
else edit2.Color := clRed;
end;
Regards, Zif.
a very easy solution is :
procedure TForm1.Edit1MouseMove(Send
Y: Integer);
begin
if (X = 0) or (X=(Sender as TEdit).width) or
(Y=0) or (Y=(Sender as TEdit).Height) then edit2.Color := clWhite
else edit2.Color := clRed;
end;
Regards, Zif.
reject my answer. Matvey's solution will be better.
Heh, OK, I'm a bit late, but here it is:
__________________________ __________ __________ __________ __________ _______
unit MUEdit;
interface
uses
Messages, Classes, Controls, StdCtrls;
type
TMUEdit = class(TEdit)
private
FOnMouseEnter: TNotifyEvent;
FOnMouseLeave: TNotifyEvent;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
published
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;
procedure Register;
implementation
procedure TMUEdit.CMMouseEnter(var Message: TMessage);
begin
inherited;
if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
end;
procedure TMUEdit.CMMouseLeave(var Message: TMessage);
begin
inherited;
if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;
procedure Register;
begin
RegisterComponents('Sample s', [TMUEdit]);
end;
end.
__________________________ __________ __________ __________ __________ _______
Install this component, and you have got the TMUEdit on the Samples panel. If you put it on your form, you have the OnMouseEnter and OnMouseLeave events which you can use with absolutely no farther work required. These events will be fired no meter which way the cursor enters or leavs the edit rectangle. Why the guys from Borland weren't so kind and did it themselvs??? :)
--Matvey
__________________________
unit MUEdit;
interface
uses
Messages, Classes, Controls, StdCtrls;
type
TMUEdit = class(TEdit)
private
FOnMouseEnter: TNotifyEvent;
FOnMouseLeave: TNotifyEvent;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
published
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;
procedure Register;
implementation
procedure TMUEdit.CMMouseEnter(var Message: TMessage);
begin
inherited;
if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
end;
procedure TMUEdit.CMMouseLeave(var Message: TMessage);
begin
inherited;
if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;
procedure Register;
begin
RegisterComponents('Sample
end;
end.
__________________________
Install this component, and you have got the TMUEdit on the Samples panel. If you put it on your form, you have the OnMouseEnter and OnMouseLeave events which you can use with absolutely no farther work required. These events will be fired no meter which way the cursor enters or leavs the edit rectangle. Why the guys from Borland weren't so kind and did it themselvs??? :)
--Matvey
ASKER
matvey
could u post it as an answer?
thanks heaps
Regards
keith
could u post it as an answer?
thanks heaps
Regards
keith
Hi Keith, glad it's one headache less!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.