AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Fokusieren des Buttons vermeiden

Offene Frage von "Stefan92"
Ein Thema von Stefan92 · begonnen am 15. Jan 2007 · letzter Beitrag vom 19. Jan 2007
 
Stefan92

Registriert seit: 9. Jan 2007
146 Beiträge
 
Delphi 7 Enterprise
 
#1

Fokusieren des Buttons vermeiden

  Alt 15. Jan 2007, 18:57
Hallo,
ich finde den Titel schon ziemlich vielsagend. Ich möchte halt, dass keiner meiner Buttons auf der gesamten Form fokusiert werden kann, und damit meine ich halt nicht nur mit der Tabulator-Taste. Ausserdem werden die meisten Buttons auch fokusiert, wenn man sie einmal anklickt, die Maustaste gedrückt hält und die Maustaste erst woanders wieder loslässt. Weiss jemand, wie man das umgehen kann? Ich habe schon überlegt, für jeden Button das Ereignis OnMouseUp zu nehmen, aber das wäre mir zu umständlich und ausserdem würde der Code dann ziemlich unübersichtlich werden (was er aber eigentlich sowieso schon ist ).
Hier mein Quellcode:
Delphi-Quellcode:
unit Taschenrechner;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ActnList, Menus, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Button14: TButton;
    Button15: TButton;
    Button16: TButton;
    Button17: TButton;
    Button18: TButton;
    Button19: TButton;
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    Beenden1: TMenuItem;
    N1: TMenuItem;
    Hilfe1: TMenuItem;
    Info1: TMenuItem;
    Panel1: TPanel;
    Button20: TButton;
    Button21: TButton;
    Button22: TButton;
    Button23: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button18Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button19Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button17Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: char);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure Beenden1Click(Sender: TObject);
    procedure Info1Click(Sender: TObject);
    procedure Panel1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button20Click(Sender: TObject);
    procedure Button21Click(Sender: TObject);
    procedure Button22Click(Sender: TObject);
    procedure Button23Click(Sender: TObject);
  private
    lism:integer; {letters in secret message}
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

var operation,strich,punkt,punktvorstrich,zahl:boolean;
    zahl1,zahl2,zahl3,result:real;
    gesucht:string;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if (panel1.caption='0') or (operation=true) then
  begin
    panel1.caption:='1';
    operation:=false;
  end
  else panel1.caption:=panel1.caption+'1';
  if strich=true then zahl:=true;
  panel1.setfocus;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if (panel1.caption='0') or (operation=true) then
  begin
    panel1.caption:='2';
    operation:=false;
  end
  else panel1.caption:=panel1.caption+'2';
  if strich=true then zahl:=true;
  panel1.setfocus;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  if (panel1.caption='0') or (operation=true) then
  begin
    panel1.caption:='3';
    operation:=false;
  end
  else panel1.caption:=panel1.caption+'3';
  if strich=true then zahl:=true;
  panel1.setfocus;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  if (panel1.caption='0') or (operation=true) then
  begin
    panel1.caption:='4';
    operation:=false;
  end
  else panel1.caption:=panel1.caption+'4';
  if strich=true then zahl:=true;
  panel1.setfocus;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  if (panel1.caption='0') or (operation=true) then
  begin
    panel1.caption:='5';
    operation:=false;
  end
  else panel1.caption:=panel1.caption+'5';
  if strich=true then zahl:=true;
  panel1.setfocus;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  if (panel1.caption='0') or (operation=true) then
  begin
    panel1.caption:='6';
    operation:=false;
  end
  else panel1.caption:=panel1.caption+'6';
  if strich=true then zahl:=true;
  panel1.setfocus;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
  if (panel1.caption='0') or (operation=true) then
  begin
    panel1.caption:='7';
    operation:=false;
  end
  else panel1.caption:=panel1.caption+'7';
  if strich=true then zahl:=true;
  panel1.setfocus;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
  if (panel1.caption='0') or (operation=true) then
  begin
    panel1.caption:='8';
    operation:=false;
  end
  else panel1.caption:=panel1.caption+'8';
  if strich=true then zahl:=true;
  panel1.setfocus;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
  if (panel1.caption='0') or (operation=true) then
  begin
    panel1.caption:='9';
    operation:=false;
  end
  else panel1.caption:=panel1.caption+'9';
  if strich=true then zahl:=true;
  panel1.setfocus;
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
  if (panel1.caption='0') or (operation=true) then
  begin
    panel1.caption:='0';
    operation:=false;
  end
  else panel1.caption:=panel1.caption+'0';
  if strich=true then zahl:=true;
  panel1.setfocus;
end;

procedure TForm1.Button18Click(Sender: TObject);
begin
  panel1.caption:='0';
  strich:=false;
  punkt:=false;
  punktvorstrich:=false;
  zahl1:=0;
  zahl2:=0;
  zahl3:=0;
  panel1.setfocus;
end;

procedure TForm1.Button12Click(Sender: TObject);
var vorzeichenwechsel:real;
begin
  vorzeichenwechsel:=strtofloat(panel1.caption);
  vorzeichenwechsel:=vorzeichenwechsel*(-1);
  panel1.caption:=floattostr(vorzeichenwechsel);
  panel1.setfocus;
end;

procedure TForm1.Panel1Click(Sender: TObject);
begin
  if panel1.caption='then panel1.caption:='0';
end;

procedure TForm1.Button19Click(Sender: TObject);
var i:integer;
    s:string;
begin
  for i:=1 to (length(panel1.caption)-1) do
  begin
    s:=s+panel1.caption[i];
  end;
  panel1.caption:=s;
  if panel1.caption='then panel1.caption:='0';
  panel1.setfocus;
end;

procedure TForm1.Button11Click(Sender: TObject);
var j:integer;
    komma:boolean;
begin
  komma:=false;
  for j:=1 to length(panel1.caption) do
  if panel1.caption[j]=',then
  begin
    komma:=true;
    break;
  end
  else komma:=false;
  if komma=false then
  begin
    panel1.caption:=panel1.caption+',';
  end;
  panel1.setfocus;
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
  panel1.setfocus;
  result:=0;
  if (zahl=false) and (strich=true) then exit;
  zahl2:=strtofloat(panel1.caption);
  if result=0 then result:=zahl2;
  if panel1.caption='0then result:=zahl2;
  if gesucht='summethen result:=zahl1+zahl2;
  if gesucht='differenzthen result:=zahl1-zahl2;
  if (gesucht='quotient') and (zahl2<>0) then result:=zahl1/zahl2
  else
  begin
    messagebox(0, 'Divison durch null nicht möglich!','Fehler',MB_OK);
    panel1.caption:='0';
  end;
  if gesucht='produktthen result:=zahl1*zahl2;
  panel1.caption:=floattostr(result);
  operation:=true;
  strich:=true; {+}
  zahl1:=strtofloat(panel1.caption);
  gesucht:='summe';
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
  panel1.setfocus;
  result:=0;
  if (zahl=false) and (strich=true) then exit;
  zahl2:=strtofloat(panel1.caption);
  if result=0 then result:=zahl2;
  if gesucht='summethen result:=zahl1+zahl2;
  if gesucht='differenzthen result:=zahl1-zahl2;
  if (gesucht='quotient') and (zahl2<>0) then result:=zahl1/zahl2
      else
      begin
        messagebox(0, 'Divison durch null nicht möglich!','Fehler',MB_OK);
        panel1.caption:='0';
      end;
  if gesucht='produktthen result:=zahl1*zahl2;
  panel1.caption:=floattostr(result);
  operation:=true;
  strich:=true; {-}
  zahl1:=strtofloat(panel1.caption);
  gesucht:='differenz';
end;

procedure TForm1.Button17Click(Sender: TObject);
begin
  if (strich=false) and (punkt=true) then
  begin
    result:=0;
    zahl2:=strtofloat(panel1.caption);
    if gesucht='summethen result:=zahl1+zahl2;
    if gesucht='differenzthen result:=zahl1-zahl2;
    if (gesucht='quotient') and (zahl2<>0) then result:=zahl1/zahl2
      else
      begin
        messagebox(0, 'Divison durch null nicht möglich!','Fehler',MB_OK);
        panel1.caption:='0';
      end;
    if gesucht='produktthen result:=zahl1*zahl2;
    panel1.caption:=floattostr(result);
    operation:=true;
  end;
  if strich=true then
  begin
    zahl2:=strtofloat(panel1.caption);
    punktvorstrich:=true;
  end;
  operation:=true;
  punkt:=true; {/}
  if punktvorstrich=false then zahl1:=strtofloat(panel1.caption);
  gesucht:='quotient';
  panel1.setfocus;
end;

procedure TForm1.Button16Click(Sender: TObject);
begin
  if (strich=false) and (punkt=true) then
  begin
    result:=0;
    zahl2:=strtofloat(panel1.caption);
    if gesucht='summethen result:=zahl1+zahl2;
    if gesucht='differenzthen result:=zahl1-zahl2;
    if (gesucht='quotient') and (zahl2<>0) then result:=zahl1/zahl2
      else
      begin
        messagebox(0, 'Divison durch null nicht möglich!','Fehler',MB_OK);
        panel1.caption:='0';
      end;
    if gesucht='produktthen result:=zahl1*zahl2;
    panel1.caption:=floattostr(result);
    operation:=true;
  end;
  if strich=true then
  begin
    zahl2:=strtofloat(panel1.caption);
    punktvorstrich:=true;
  end;
  operation:=true;
  punkt:=true; {*}
  if punktvorstrich=false then zahl1:=strtofloat(panel1.caption);
  gesucht:='produkt';
  panel1.setfocus;
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
  result:=0;
  if punktvorstrich=false then zahl2:=strtofloat(panel1.caption);
  if (zahl1=0) and (punkt=false) then panel1.caption:=floattostr(zahl2)
  else
  begin
    if punktvorstrich=true then
    begin
      zahl3:=strtofloat(panel1.caption);
      result:=(zahl2*zahl3)+zahl1;
      panel1.caption:=floattostr(result);
    end
    else
    begin
      if gesucht='summethen result:=zahl1+zahl2;
      if gesucht='differenzthen result:=zahl1-zahl2;
      if (gesucht='quotient') and (zahl2<>0) then result:=zahl1/zahl2
      else
      begin
        messagebox(0, 'Divison durch null nicht möglich!','Fehler',MB_OK);
        panel1.caption:='0';
      end;
      if gesucht='produktthen result:=zahl1*zahl2;
      panel1.caption:=floattostr(result);
    end;
  end;
  operation:=true;
  strich:=false;
  punkt:=false;
  punktvorstrich:=false;
  panel1.setfocus;
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
var easterstring:string;
begin
  easterstring:='';
  case key of
    '1' : button1.click;
    '2' : button2.click;
    '3' : button3.click;
    '4' : button4.click;
    '5' : button5.click;
    '6' : button6.click;
    '7' : button7.click;
    '8' : button8.click;
    '9' : button9.click;
    '0' : button10.click;
    ',' : button11.click;
    '.' : button11.click;
    'n' : button12.click;
    chr(13) : button13.click;
    '-' : button14.click;
    '+' : button15.click;
    '*' : button16.click;
    '/' : button17.click;
    chr(8) : button19.click;
    'p' : button20.click;
    'w' : button21.click;
    'q' : button22.click;
    'r' : button23.click;
  else
  begin
    easterstring:=easterstring+key;
    if Copy('test', 1, Length(easterstring))<>easterstring then easterstring:='';
    if easterstring='testthen showmessage('hui');
  end;
  end;
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
const hiddenmessage='SEBI';
      messagelen=length(hiddenmessage);
begin
  if key = vk_Delete then button18.click;
  if ssCtrl in Shift then
  begin
    if key=ord(hiddenmessage[lism]) then
    begin
      if lism=messagelen then
      begin
        messagebox(0,'Vielen Dank, für die Ermöglichung meines '+
        'allerersten Programmes!','Danke', MB_OK);
        lism:=1;
      end
      else
      begin
        inc(lism)
      end;
    end
    else if key=ord(hiddenmessage[1]) then lism:=2 else lism:=1;
  end;
end;

procedure TForm1.Beenden1Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.Info1Click(Sender: TObject);
var s:pansichar;
begin
  s:='Programmiert von: ...'+#13+'Designt von: ...'+
  #13+'Inspiriert von: ...'+#13+'Version: 1.2';
  messagebox(0, s, 'Info', MB_OK);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  keypreview:=true;
  lism:=1;
end;

procedure TForm1.Button20Click(Sender: TObject);
begin
  panel1.caption:=floattostr(3.14159265358979);
end;

procedure TForm1.Button21Click(Sender: TObject);
var wurzel:real;
begin
  wurzel:=strtofloat(panel1.caption);
  wurzel:=sqrt(wurzel);
  panel1.caption:=floattostr(wurzel);
end;

procedure TForm1.Button22Click(Sender: TObject);
var Quadrat:real;
begin
  quadrat:=strtofloat(panel1.Caption);
  quadrat:=sqr(quadrat);
  panel1.caption:=floattostr(quadrat);
end;

procedure TForm1.Button23Click(Sender: TObject);
var x:real;
begin
  x:=strtofloat(panel1.Caption);
  if x<>0 then x:=1/x else
  begin
    messagebox(0, 'Divison durch null nicht möglich!','Fehler',MB_OK);
    panel1.caption:='0';
  end;
  panel1.caption:=floattostr(x);
end;

end.
Hoffe ihr könnt mir helfen und danke schonmal im Voraus.
Und wenn ihr Lust habt, könnt ihr meinen Code auch beurteilen bzw. kritisieren.

Gruß

Stefan

[edit=r_kerber]code durch delphi-Tags ersetzt. Mfg, r_kerber[/edit]

Geändert von MrSpock ( 4. Sep 2012 um 15:04 Uhr) Grund: Namen aus dem Code auf Wunsch des TE gelöscht.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03: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