2D Array und MausPosition
Hallo,
wie kann herrausfinden in welchem kasten der Mauscursor grade ist und dann in einen Label z.B. X: 1 Y: 2 anzeigen? |
Re: 2D Array und MausPosition
Zitat:
|
Re: 2D Array und MausPosition
Delphi-Quellcode:
das ist doch mal ein anfang?!
procedure TForm1.Button1Click(Sender: TObject);
var p: TPoint; begin GetCursorPos(p); Button1.Caption := 'X: ' + IntToStr(p.X) + ', Y: ' + IntToStr(p.Y); end; |
Re: 2D Array und MausPosition
Naja, also ich hab folgenden Code.
Delphi-Quellcode:
Also hab ich quasi 32*32 Große kästen 6 Waagerecht und
var map: Array[0..6,0..6] of Integer;
x, y: Integer; begin for x := 0 to 6 do for y := 0 to 6 do begin Map[x,y] := 0; if Map[x,y] = 0 then Image1.Canvas.Draw(x*32,y*32, Image2.Picture.Bitmap); end; end; 6 Senkrecht. Nun möchte ich anzeigen auf welchem 32*32 Großen Kasten der Mauscursor sich befindet. Also 1 Waagrecht, 2 Senkrecht |
Re: 2D Array und MausPosition
dann schau dir mal die funktion "ClientToScreen" an.
|
Re: 2D Array und MausPosition
Hab mir dir function mal in der OH angeschaut. Dort steht etwas von
Delphi-Quellcode:
Irgendwie weiß ich nicht, dies in meinem Code anzuwenden.
P := TargetControl.ScreenToClient(SourceControl.ClientToScreen(P));
|
Re: 2D Array und MausPosition
Die Mausposition jeweils durch 32 teilen, würd ich ma sagen, also mausposition div 32 o.ä.
|
Re: 2D Array und MausPosition
Hab es jetzt so gemacht. Klappt wunderbar. Danke euch beiden.
Delphi-Quellcode:
procedure TMainFrm.SpielfeldMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer); begin Label1.Caption := 'X: ' + IntToStr(x div 32) + ' | Y: ' + IntToStr(y div 32); end; |
Re: 2D Array und MausPosition
Sorry!
probier mal folgendes:
Delphi-Quellcode:
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); begin // SetRoundMode(rmDown); // erstes kästchen wird zu 0|0 SetRoundMode(rmUp); // erstes Kästechen wird zu 1|1 ShowMessage('X: ' + IntToStr(round(X/32)) + ', Y: ' + IntToStr(round(Y/32))); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:35 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz