Home > Back-end >  Delphi how dynamic response message?
Delphi how dynamic response message?

Time:09-28

There are three buttons, for example,
After 1 press the mouse button, the button 2 above, release the mouse,
The result is 1 in response to release the mouse button event.

How to do it after 1 press the mouse button, the button is released 2 by 2 response button, the button 3 release by the button 3 response?

CodePudding user response:

On the table for the and button2:
 
Var
Form1: TForm1;

Implementation

{$R *. DFM}
Var
Dragpoint: tpoint;//mouse press starting point
Inbutton2rect: Boolean;
Procedure TForm1. Button1MouseDown (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
The begin
Dragpoint:=point (x, y);
end;

Procedure TForm1. Button1MouseMove (Sender: TObject; Shift: TShiftState; X,
Y: Integer);
Var
Pt: tpoint;
The begin

//move to omit it too small

If (DragPoint. X=1) or ((Shift & lt;> [ssLeft]) and (Shift & lt;> [ssRight])) or
((abs (DragPoint. X - X) & lt; (10) and abs (DragPoint. Y - Y) & lt; 10)), then the exit;

Pt:=point (x + for the Left, y +. For the Top).
If ptinrect (button2 boundsrect, pt) then
The begin

Caption:='button2 In the rect';
Inbutton2rect:=true;
End the else
The begin
Caption:='Not in button2 the rect';
Inbutton2rect:=false;
end;
end;

Procedure TForm1. Button1MouseUp (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
The begin
//on the button2 loosen the mouse events
If inbutton2rect then
The begin
Button2. SetFocus;//as if ordered button2
Button2. Click;//button2 action

end;
end;

Procedure TForm1. Button2Click (Sender: TObject);
The begin
Showmessage (' button2 click ');
end;

End.

CodePudding user response:

reference 1st floor FRTRNR response:
on the table for the and button2:
 
Var
Form1: TForm1;

Implementation

{$R *. DFM}
Var
Dragpoint: tpoint;//mouse press starting point
Inbutton2rect: Boolean;
Procedure TForm1. Button1MouseDown (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
The begin
Dragpoint:=point (x, y);
end;

Procedure TForm1. Button1MouseMove (Sender: TObject; Shift: TShiftState; X,
Y: Integer);
Var
Pt: tpoint;
The begin

//move to omit it too small

If (DragPoint. X=1) or ((Shift & lt;> [ssLeft]) and (Shift & lt;> [ssRight])) or
((abs (DragPoint. X - X) & lt; (10) and abs (DragPoint. Y - Y) & lt; 10)), then the exit;

Pt:=point (x + for the Left, y +. For the Top).
If ptinrect (button2 boundsrect, pt) then
The begin

Caption:='button2 In the rect';
Inbutton2rect:=true;
End the else
The begin
Caption:='Not in button2 the rect';
Inbutton2rect:=false;
end;
end;

Procedure TForm1. Button1MouseUp (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
The begin
//on the button2 loosen the mouse events
If inbutton2rect then
The begin
Button2. SetFocus;//as if ordered button2
Button2. Click;//button2 action

end;
end;

Procedure TForm1. Button2Click (Sender: TObject);
The begin
Showmessage (' button2 click ');
end;

End.

CodePudding user response:

Actually, this is the Delphi a custom rules, internal have a CaptureControl used to capture control, also have a CsCapture remember ControlState seemingly, is said to capture the control, if capture mode, the mouse to press, no matter where they should let go of the mouse, is the capture control trigger MouseUp news, ideas into can try from now on, to this kind of model do effect a radical cure, instead you want to deal with all the controls of the above processing
  • Related