比如有三個按鈕,
在按鈕1按下滑鼠后, 在按鈕2上面釋放滑鼠,
結果是按鈕1在回應釋放滑鼠的事件.
怎樣做到 在按鈕1按下滑鼠后, 在按鈕2釋放就由按鈕2回應,在按鈕3釋放就由按鈕3回應?
uj5u.com熱心網友回復:
表上放button1和button2:
var
Form1: TForm1;
implementation
{$R *.dfm}
var
dragpoint:tpoint; //滑鼠按下起始點
inbutton2rect:boolean;
procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
dragpoint:=point(x,y);
end;
procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
pt:tpoint;
begin
// 移動過小就忽略
if (DragPoint.X = -1) or ((Shift <> [ssLeft]) and (Shift <> [ssRight])) or
((abs(DragPoint.X - X) <10) and (abs(DragPoint.Y - Y) <10)) then exit;
pt:=point(x+button1.Left,y+button1.Top);
if ptinrect(button2.boundsrect, pt) then
begin
caption:= 'In button2 rect';
inbutton2rect:=true;
end else
begin
caption:= 'Not in button2 rect';
inbutton2rect:=false;
end;
end;
procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//在button2上松開滑鼠的事件
if inbutton2rect then
begin
button2.SetFocus;// 好像點了button2
button2.Click; // button2動作
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage('button2 click');
end;
end.
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
其實,這個是Delphi自定義的一個規則,內部有一個CaptureControl用來捕捉控制元件,貌似記得ControlState也有一個CsCapture的,表示是否對該控制元件進行捕捉,如果捕捉模式下,則滑鼠按下之后,無論到什么地方放開滑鼠,都是本捕捉控制元件的MouseUp訊息觸發,可以嘗試從此思路進入,對此類模式做到根治,而不用對你想要處理的所有控制元件都做以上處理轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/87380.html
標籤:語言基礎/算法/系統設計
上一篇:滑鼠模擬,程式失去焦點后不起作用
