全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1826
推到 Plurk!
推到 Facebook!

取得上層圖片的滑鼠座標

尚未結案
mike1000
一般會員


發表:2
回覆:5
積分:1
註冊:2011-06-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2011-12-08 18:20:45 IP:124.219.xxx.xxx 訂閱
各位好:

小弟現有兩張圖片 image1 , image2 (image1 在 image2 "-底圖" 的圖片上面) , 是否能在拖動 image1時, 仍能取得 image2的滑動座標, 因為只能得到 image1 的 mousemove
事件, 而無法得到 image2 的觸發事件, 能否有方法同時可以得到兩張圖對應的滑鼠移動事件(即 x1,y1 及 x2,y2), 或是簡單而說,如何可以得知 image1的 Left , Top 位於 image2 的
移動位置, 謝謝幫忙!!
smallfox
高階會員


發表:2
回覆:113
積分:128
註冊:2003-02-19

發送簡訊給我
#2 引用回覆 回覆 發表時間:2011-12-09 00:08:30 IP:175.181.xxx.xxx 訂閱
以下程式碼是用 Delphi 寫的, 原理差不多, 請參考翻寫 ...

// ---------------------------------------------------------------
interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, jpeg, ExtCtrls;

type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
X1, X2, Y1, Y2: Integer;
mDown: Boolean;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mDown:=False;
Label2.Caption:='Left: ' IntToStr(Image2.Left) ', Top: ' IntToStr(Image2.Top);
Label4.Caption:='Width: ' IntToStr(Image2.Width) ', Height: ' IntToStr(Image2.Height);
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
// 相對於 Form1 的座標值 ..
X2:=Image1.Left X;
Y2:=Image1.Top Y;
//
X1:=X;
Y1:=Y;
mDown:=True;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var Image2_X, Image2_Y: Integer;
begin
if (mDown) then
begin
X2:=X2 (X-X1);
Y2:=Y2 (Y-Y1);
Label1.Caption:='X: ' IntToStr(X2) ', Y: ' IntToStr(Y2);
//
// 落點於 Image2 範圍內, 算出在 Image2 內的座標值 ...
if ((X2>=Image2.Left) and (X2<=Image2.Left Image2.Width-1)) and
((Y2>=Image2.Top) and (Y2<=Image2.Top Image2.Height-1)) then begin
Image2_X:=X2-Image2.Left;
Image2_Y:=Y2-Image2.Top;
Label3.Caption:='X: ' IntToStr(Image2_X) ', Y: ' IntToStr(Image2_Y);
end;
//
Image1.Left:=Image1.Left (X-X1);
Image1.Top :=Image1.Top (Y-Y1);
end
else
Label1.Caption:='X: ' IntToStr(X) ', Y: ' IntToStr(Y);
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
mDown:=False;
end;

end.
系統時間:2024-03-28 19:26:31
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!