Autor Beitrag
Wolfgang
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Di 17.01.06 10:13 
Hi!

Ich würde gerne in einem Programm die Pfeiltasten deaktivieren oder einfach nur verhindern, dass sie auf einen Druck reagieren.

Könntet ihr mir vielleict weiterhelfen?

thx im Vorhinein.

PS: Warum werden mir bei diesem Quellcode manchmal Scrollbalken anezeigt, obwohl ich die Höhe und Breite extra um die Höhe und Breite des Buttons reduziert habe?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
label anfang;
begin

anfang:

randomize;
button1.Top:=random(form1.Height-button1.Height);
button1.left:=random(form1.width-button1.width);
if button1.top=button2.Top then goto anfang;
if button1.Left=button2.Left then goto anfang;

end;
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 17.01.06 10:41 
zum Beispiel so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key in [chr(vk_left),chr(vk_right)] then
  begin
    Key := #0;
  end;
end;


Und dein Source mit Label und Goto :mahn: . Sowas macht man doch nicht mit Delphi :wink:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  randomize; // Bitte nur einmal aufrufen
  repeat
    button1.Top:=random(form1.Height-button1.Height);
    button1.left:=random(form1.width-button1.width);
  until (button1.top <> button2.Top) and (button1.Left <> button2.Left)
end;
Wolfgang Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Di 17.01.06 11:31 
Danke für deine Hilfe.

Ah und sorry wegen dem Label :oops: werds gleich ändern!

_________________
Two or three tons of stone can really get you down, and keep you there!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 17.01.06 12:23 
user profile iconWolfgang hat folgendes geschrieben:
Ah und sorry wegen dem Label :oops: werds gleich ändern!

War nicht so gemeint. Wir alten Kerle reagieren da einfach nur empfindlich. Wenn es nicht erforderlich ist, sollte man Goto u.ä. vermeiden. Ist aber eher eine Frage des Programmierstils.
Wolfgang Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Mi 18.01.06 09:33 
Hi jacoul!

Ich habe das mit dem Keypress ausprobiert. Jedoch fonktioniert es nicht.
Hab ich da was falsch gemacht oder ist es der falsche Lösungsweg für mein Progamm?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
if Key in [chr(vk_left),chr(vk_right),chr(vk_up),chr(vk_down)] then
begin
  Key := #0;
end;


Ich will ein kleines Programm schreiben, bei dem in einem Label die Frage steht "Wollen Sie eine Gehaltserhöhung?". Außerdem gibt es 2 Buttons "Ja" und "Nein". Der "Ja"-Button springt weg, sobald man mit der Maus darüber fährt. Der Tabstop wurde deaktiviert, nur mit den Pfeiltasten erreiche ich den Button noch.

Meine stupide und unschöne Lösung: Timer, der alle 1/1000 Sekunden die Activecontrol auf den "Nein"-Button" setzt.

Wie geht das besser?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 18.01.06 09:47 
Hast du geprüft, ob das KeyPreview der Form auf True?

Ich habe das gerade mal mit Checkboxen ausprobiert. KeyPress und KeyDown werden gar nicht ausgelöst und KeyUp ist einfach zu spät. Warum das so ist, kann ich mir grob vorstellen, aber das hilft hier jetzt nicht weiter.

Probier doch mal, ob dir das OnExit-Ereignis weiter hilft. Oder hat noch jemand eine bessere Idee?
Wolfgang Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Mi 18.01.06 10:40 
Hi!

Ich hab mein Programm im Dateianhang als zip file.

Wenn du dir das ansiehst, kannst du mir auch vielleicht auch gleich sagen, warum ich teilweise bei der Form die scrollbalken bekomme, obwohl ich Button1.top zufällich von Form1.Height-Button1.Height und Button1.Left zufällig von Form1.Width-Button1.Width errechne.

thx Wolfgang
Einloggen, um Attachments anzusehen!
_________________
Two or three tons of stone can really get you down, and keep you there!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 18.01.06 10:50 
Hast eigentlich alles richtig gemacht. Allerdings wird das Ereignis nie aufgerufen. Die Gründe liegen irgendwo in Windows versteckt.

Folgende Lösung führt auch zum Ziel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1Enter(Sender: TObject);
begin
  Button2.SetFocus;
end;


Zu deinem Problem mit den Scroll-Balken:
Du musst bei der Positionierung deines Buttons noch die Größe der Fläche der Form beachten und die Größe des Buttons selbst. Sonst landet der Button außerhalb des sichtbaren Bereichs.
Wolfgang Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Mi 18.01.06 10:57 
Danke

Ich dachte, dass ich die Größe der Form und die Größe des Buttons bereits mit
ausblenden Delphi-Quelltext
1:
2:
button1.Top:=random(form1.Height-button1.Height);
button1.left:=random(form1.width-button1.width);

beachtet habe.

Moderiert von user profile iconGausi: Beitragsformatierung überarbeitet.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 18.01.06 11:39 
Die Form ist aber größer als die nutzbare Fläche. Du musst noch den Form-Balken (oben) und die Ränder berücksichtigen.