Autor Beitrag
Kuja
Hält's aus hier
Beiträge: 15



BeitragVerfasst: Do 11.05.06 19:08 
Hallo,
ich möchte bei bestimmten x, y Koordinaten einen Text bei Mouseover ausgeben.

Sprich wenn der Cursor diesen festgelegten Bereich berührt oder "überfährt" soll eine Nachricht ausgegeben werden.

Weiß jemand wie ich das ermöglichen kann? :)

Schonmal danke,

Kuja
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 11.05.06 19:10 
Ist das ein Punkt oder eine Fläche?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Kuja Threadstarter
Hält's aus hier
Beiträge: 15



BeitragVerfasst: Do 11.05.06 19:12 
Ein Shape :)
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 11.05.06 19:14 
Du nimmst einen Timer und fragst die Mauskoordinaten ab:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var x,y:integer;

x:=mouse.cursorpos.x;
y:=mouse.cursorpos.y;

Dann musst du im Timer noch abfragen, ob die Maus sich über dem Shape befindet. Probiere es erst einmal alleine ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Kuja Threadstarter
Hält's aus hier
Beiträge: 15



BeitragVerfasst: Do 11.05.06 20:03 
Hallo! :)

Habe mir in der Delphi Hilfe nun mal den Timer angeschaut und auch aktivieren können, nur erahne ich da eine
Überschneidung mit meinem bisherigen Code.

Als der wäre:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
unit labyrinth;

interface

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

type
  TForm1 = class(TForm)
    Shape1: TShape;
    Shape2: TShape;
    Shape4: TShape;
    Shape5: TShape;
    Shape7: TShape;
    Shape8: TShape;
    Shape9: TShape;
    Shape10: TShape;
    Shape11: TShape;
    Shape12: TShape;
    Shape13: TShape;
    Shape3: TShape;
    Shape6: TShape;
    Image1: TImage;
    Timer1: TTimer;
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  MyText: string;
  OldX, OldY: Integer;
  x, y: Integer;

implementation

{$R *.DFM}

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
    MyText:= '';
     if x<OldX then begin
     // ab nach links
     MyText:= 'Links/';
     end else
     if x>OldX then begin
     //ab nach rechts
     MyText:= 'Rechts/';
     end else begin
     // x bleibt
     MyText:= '-/';
     end;

     if y<OldY then begin
     // ab nach oben
     MyText:= MyText+'Hoch';
     end else
     if y>OldY then begin
     // ab nach unten
     MyText:= MyText+'Runter';
     end else begin
     // y bleibt
     MyText:= MyText+'-';
     end;
     Form1.Caption:= MyText;
     OldX:= x;
     OldY:= y;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     setcursorpos (form1.left + 390, form1.top + 405);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin

end;

end.


Sollte ich den Timer mit der procedure FormMouseMove verbinden?

Ich würde nun annehmen dass ich bei
procedure TForm1.Timer1Timer(Sender: TObject)
begin
(so etwas wie) if x=100 then Caption.Label1 (was ich dann noch erstelle) := 'Du darfst das Shape nicht berühren!';
schreiben soll.

Stimmt das im Ansatz? :D

Habe wie gesagt Sorge dass sich das mit dem MyText Code überschneidet...

Danke und viele Grüße,

Kuja
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 11.05.06 20:11 
Im Ansatz schon. Aber was ist, wenn x=99, dann kann er ja auch auf das Shape ;)
Besser wäre eine Abfrage, ob der Cursor auf der x-Achse zwischen dem linken und dem rechten Ende und auf der y-Achse zwischen oberem und unterem Ende des Shapes liegt, wenn beides zutrifft, muss er drauf sein ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Kuja Threadstarter
Hält's aus hier
Beiträge: 15



BeitragVerfasst: Do 11.05.06 20:16 
Ja das stimmt natürlich, nur es ging mir eher allgemein um die Ausgabe! :)

Sagen wir mal ich schreibe:

if x=198 and y=356 then Label1.Caption (hatte es verdreht :D) := 'Du darfst das Shape nicht berühren!';

Würde dies funktionieren? Ich kriege einen Error aber bin mir ja eh nicht ganz sicher! :p

1.) Trennt man Variablen wie x und y mit "and"? Oder durch ein Komma o.a.?
2.) Was ist mit meinem MyText Code? Keine Überschneidung dadurch?

Ich näher mich der Sache, wenn auch langsam... ;)

Danke und viele Grüße,

Kuja
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 11.05.06 20:20 
ausblenden Delphi-Quelltext
1:
if (x>shape1.left) and (x<shape1.left+shape1.width) and (y>shape1.top) and (y<shape1.top+shape1.height) then showmessage('Drauf!!!!');					

Das mit der Überschneidung versteh ich nicht.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Kuja Threadstarter
Hält's aus hier
Beiträge: 15



BeitragVerfasst: Do 11.05.06 20:30 
Erklärung bitte was du geschrieben hast! =)

Dadurch funktioniert aber leider auch nichts weiteres, obwohl es sehr logisch klingt! :S

Mit der Überschneidung meine ich ob durch diesen Teil des Programms:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
    MyText:= '';
     if x<OldX then begin
     // ab nach links
     MyText:= 'Links/';
     end else
     if x>OldX then begin
     //ab nach rechts
     MyText:= 'Rechts/';
     end else begin
     // x bleibt
     MyText:= '-/';
     end;

     if y<OldY then begin
     // ab nach oben
     MyText:= MyText+'Hoch';
     end else
     if y>OldY then begin
     // ab nach unten
     MyText:= MyText+'Runter';
     end else begin
     // y bleibt
     MyText:= MyText+'-';
     end;
     Form1.Caption:= MyText;
     OldX:= x;
     OldY:= y;
end;


möglicherweise eine Ausgabe verhindert wird. :)

Denn im Prinzip erscheint mir dein Code logisch nur wie gesagt es passiert nichts...

Es ist aber schon richtig dass dein Code im Timer implementiert wurde oder?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
     if (x>shape1.left) and (x<shape1.left+shape1.width) and (y>shape1.top) and (y<shape1.top+shape1.height) then showmessage('Drauf!!!!');
end;


Gracias,

Kuja
Kuja Threadstarter
Hält's aus hier
Beiträge: 15



BeitragVerfasst: Do 11.05.06 21:09 
Habe das Problem nun etwas "vereinfacht":

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
unit labyrinth;

interface

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

type
  TForm1 = class(TForm)
    Shape1: TShape;
    Shape2: TShape;
    Shape4: TShape;
    Shape5: TShape;
    Shape7: TShape;
    Shape8: TShape;
    Shape9: TShape;
    Shape10: TShape;
    Shape11: TShape;
    Shape12: TShape;
    Shape13: TShape;
    Shape3: TShape;
    Shape6: TShape;
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
    procedure Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
     setcursorpos (form1.left + 390, form1.top + 405);
end;

procedure TForm1.Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
     Showmessage('Nicht den Rand berühren! :)');
end;

end.


Funktioniert genauso wie ich wollte, jetzt fehlt nur noch ein kleine Schritt. Dazu wieder 2 Fragen! :)

1.) Muss ich für jedes Shape die selbe procedure schreiben oder kann ich die per Array o.a. zusammenfassen?
2.) Kann ich festlegen dass der Cursor wieder an die Startposition gesetzt wird

(zur Erinnerung:)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.FormCreate(Sender: TObject);
begin
     setcursorpos (form1.left + 390, form1.top + 405);
end;


nachdem das MouseMove Ereignis ausgelöst wurde?

Danke und viele Grüße,

Kuja