Autor Beitrag
110022
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Fr 21.12.07 13:27 
wie mache is es , dass ein button gedrückt wir wenn ich auf enter drücke? also ohne maus.
Alpha_Wolf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 297

Ubuntu, Win XP, Win Vista
C#, Delphi 6 Prof, Delphi 2007 Prof, Java
BeitragVerfasst: Fr 21.12.07 13:33 
Im OI des Formulars KeyPreview auf true setzen.

Folgenden Code verwenden:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 If (Key = 13then Button1Click(self);
end;


Aber bitte das nächste mal die Forumssuche verwenden.. ;)

_________________
Diskutiere nie mit einem Irren - er zieht dich auf sein Niveau und schlägt dich mit seiner Erfahrung.
klezmor
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 558


delphi 6 personal delphi 2005 personal
BeitragVerfasst: Fr 21.12.07 13:35 
Wahrscheinlich wirst du schon festgestellt haben, dass wenn dein Button den Fokus besitzt(ein kleiner punktierter Rahmen), die Buttonroutine automatisch bei Enter ausgelöst wird. Um den Fokus zu setzen kannst du die funktion button2.SetFocus aufrufen.

_________________
"Beware of bugs in the above code; I have only proved it correct, not tried it." Donald Knuth
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Fr 21.12.07 13:49 
Hehe, ein TButton besitzt die Eigenschaft Default. Wenn du diese auswählst, wird der Button, egal welches Element den Fokus besitzt, gedrückt. Der Button wird übrigens stärker dargestellt, so wie der OK-Button in Dialogfenstern. Ich denke, das ist die profionellste Variante.
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Fr 21.12.07 14:00 
wo kann ich diese default eigenschaft denn einstellen?
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Fr 21.12.07 14:04 
im objektinspektor! Dieses schmale fenster mit den Eigenschaften usw. Die Eigenschaften sind alphabetisch sortiert. Du musst den Button 1x anklicken und dann im Objektinspektor die eigenschaft "Default" von False auf True setzen.

Kleine Anmerkung: Die Eigenschaft Cancel ist das selbe nur mit der Esc-Taste.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.