Autor Beitrag
rizor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 03.03.07 19:40 
Hi,

ich möchte ein Image als Button benutzen.

Der Code sieht folgender maßen aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TWindow.UserKlick(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if SSLeft in Shift then
  if  (X >= 370) and (X <= 715) and (Y >= 151) and (Y <= 222) then
  begin
    AirlineCreateUser.Show;
    close;
  end;
end;


Wieso reagiert das Programm nicht?
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Sa 03.03.07 20:04 
Warum benutzt du denn nicht das TImage?
Das hat doch ein OnClick ereignis.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 03.03.07 20:05 
Weil mein Image gleichzeitig ein hintergrund bild ist und über die gesamte Form ausgebreitet ist.
auf dem Bild ist halt ein Bereich.
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Sa 03.03.07 20:12 
Ich weis nicht ob die Lösung elegant ist ..

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var mpoint: TPoint;
begin
  GetCursorPos(mpoint);
  mpoint := screentoclient(mpoint);
  if (if  (mpoint.X >= 370) and (mpoint.X <= 715) and (mpoint.Y >= 151) and (mpoint.Y <= 222) then
    begin 
      AirlineCreateUser.Show; 
      close; 
  end; 
end;


das packste ins ereignis beim mausklick rein Ich hoffe das Funkioniert so.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 03.03.07 20:16 
Funktioniert leider nicht.
Der Code sieht jetzt so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TWindow.FormMouseMove(Sender: TObject);
var mpoint: TPoint;
begin
  GetCursorPos(mpoint);
  mpoint := screentoclient(mpoint);
  Edit1.Text := IntToStr(mpoint.X);
  Edit2.Text := IntToStr(mpoint.Y);
  if (mpoint.X >= 370) and (mpoint.X <= 715) and (mpoint.Y >= 151) and (mpoint.Y <= 222) then
    begin
      AirlineCreateUser.Show;
      close;
  end;
end;


Die Edits sind auch leer.
Also fragt er nicht die Position ab.
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: Sa 03.03.07 20:22 
Hältst Du denn auch die linke Shift-Taste beim Klicken mit der Mouse gedrückt?

Wenn Du abfragen möchtest, ob die linke Moustaste gedrückt wurde, musst Du das in etwa so machen:
ausblenden Delphi-Quelltext
1:
2:
if Button = mbLeft then
...
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Sa 03.03.07 20:22 
Es liegt an deiner Procedure.
Wenn du das auf ein ButtonKlick event haust Tut er alles auslesen.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 03.03.07 20:24 
Ok. Hab ich nun geändert, aber das Problem ist, dass er die Mausposition nicht abfragt, da die Edits leer bleiben.
Ich verstehe nicht warum.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TWindow.FormMouseClick(Sender: TObject);
var
  Key : TMouseButton;
  mpoint : TPoint;
begin
if Key = mbLeft then
begin
  GetCursorPos(mpoint);
  mpoint := screentoclient(mpoint);
  Edit1.Text := IntToStr(mpoint.X);
  Edit2.Text := IntToStr(mpoint.Y);
  if (mpoint.X >= 370) and (mpoint.X <= 715) and (mpoint.Y >= 151) and (mpoint.Y <= 222) then
    begin
      AirlineCreateUser.Show;
      close;
  end;
end;
end;
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 03.03.07 20:25 
user profile iconSimak hat folgendes geschrieben:
Es liegt an deiner Procedure.
Wenn du das auf ein ButtonKlick event haust Tut er alles auslesen.


Das verstehe ich nicht.
Beschreib mal bitte genauer.
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Sa 03.03.07 20:37 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
var mpoint: TPoint;
begin
  GetCursorPos(mpoint);
  mpoint := screentoclient(mpoint);
  Edit1.Text := IntToStr(mpoint.X);
  Edit2.Text := IntToStr(mpoint.Y);
  if (mpoint.X >= 370) and (mpoint.X <= 715) and (mpoint.Y >= 151) and (mpoint.Y <= 222) then
    begin
    end;
end;

Die obere funktioniert
Beim unteren weis ich leider auch nicht warum ich denke mal, dass das so nicht hinhaut mit "procedure TWindow.FormMouseClick(Sender: TObject);"

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TWindow.FormMouseClick(Sender: TObject); 
var 
  Key : TMouseButton; 
  mpoint : TPoint; 
begin 
if Key = mbLeft then 
begin 
  GetCursorPos(mpoint); 
  mpoint := screentoclient(mpoint); 
  Edit1.Text := IntToStr(mpoint.X); 
  Edit2.Text := IntToStr(mpoint.Y); 
  if (mpoint.X >= 370) and (mpoint.X <= 715) and (mpoint.Y >= 151) and (mpoint.Y <= 222) then 
    begin 
      AirlineCreateUser.Show; 
      close; 
  end; 
end; 
end;
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: Sa 03.03.07 20:40 
user profile iconrizor hat folgendes geschrieben:
Ok. Hab ich nun geändert, aber das Problem ist, dass er die Mausposition nicht abfragt, da die Edits leer bleiben.
Ich verstehe nicht warum.

Ähh... eigentlich habe ich Dein zuerst geposteten Quellcode gemeint; hätte ich vielleicht erwähnen sollen.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 03.03.07 20:42 
Das ist ja nicht das Problem, denn wenn ich klicke müsste er auch so die position ausgeben, was er aber nicht tut.
Wie soll ihc das sonst mit der Abfrage mache?
ich kann ja schlecht ein button einbauen.
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Sa 03.03.07 20:43 
Bist du sicher, dass deine Mouse-Events überhaupt deine Behandlungsroutinen aufrufen, und nicht schon im Image hängen bleiben, welches - wie du selber sagst - über die ganze Form geht.

Was ist überhaupt TWindow?
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 03.03.07 21:01 
TWindow ist im Prinzip mein Form1.
Wie kann ich prüfen, ob die Werte hängen bleiben?
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Sa 03.03.07 21:21 
user profile iconrizor hat folgendes geschrieben:
TWindow ist im Prinzip mein Form1.
Wie kann ich prüfen, ob die Werte hängen bleiben?

Indem du Haltepunkte in deine Behandlungsroutinen setzt.

Ich denke, du wirst dann feststellen, dass dieser Haltepunkt nie erreicht wird - was meine Vermutungen bestätigen würde.

Also: Wenn du mit der Maus über das Image schlitterst und darauf herumklickst, dann wird dein Image die Ereignisse erhalten und nicht das Form. Das Form liegt unter dem Image und kriegt von den Mausereignissen nichts mit.

Baue also die Geschichten in Ereignisbehandlungsroutinen vom Image ein. Das dürfte helfen.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: So 04.03.07 00:36 
Hat geholfen.
Danke hattest recht.