Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi combobox und tastatur (https://www.delphipraxis.net/91865-combobox-und-tastatur.html)

Marco Steinebach 11. Mai 2007 00:41


combobox und tastatur
 
Hallo listers,
ich hab 'ne Denkblockade! ;-)
Mein Form hat eine ComboBox, da steht eine zahl drin. Jetz thätte ich gern, wenn ich ein + (plus) drücke, wird die zahl um 1 erhöht.
Ich dachte, gut, schreibst du genau das ins OnChange rein. Geht auch, aber nur, wenn nichts selektiert ist. Wie aber kriege ich es hin, das es funktioniert, wenn's selektiert ist: Dann nämlich erscheint mir nur das + im OnChange?
Sinn, daß der User nicht darauf achten muß, ob er was selektiert hat oder nicht, sondern den Wert einfach mit plus erhöhen kann.
Das Plus im KeyPress oder OnKey abzufangen macht leiderkeinen unterschied. Problem ist, daß OnChange erst NACH der änderung eintritt.
Hiiiiilfe! ;-)
Viele grüße
Marco

DelphiProgrammierer 11. Mai 2007 00:57

Re: combobox und tastatur
 
Mmm... folgender Code funktioniert bei mir, auch wenn etwas selektiert ist (Style is csDropDown). Geht dann auch über die 5 hinaus.

Delphi-Quellcode:
  object ComboBox1: TComboBox
    Left = 160
    Top = 144
    Width = 145
    Height = 21
    ItemHeight = 13
    TabOrder = 2
    Text = '1'
    OnKeyPress = ComboBox1KeyPress
    Items.Strings = (
      '1'
      '2'
      '3'
      '4'
      '5')
  end
Delphi-Quellcode:
procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key='+' then
  begin
    Key := #0;
    ComboBox1.Text := IntToStr(StrToInt(ComboBox1.Text)+1);
  end;
end;

Marco Steinebach 11. Mai 2007 12:55

Re: combobox und tastatur
 
Hallo,

Zitat:

Zitat von DelphiProgrammierer
Mmm... folgender Code funktioniert bei mir, auch wenn etwas selektiert ist (Style is csDropDown). Geht dann auch über die 5 hinaus.

ja, bei mir auch! ;-) So was bescheuertes. Ich hab mit
Delphi-Quellcode:
Key := #0
rumgebastelt, aber NACH der zuweisung, dann gibts nämlich blödsinn!

Vielen herzlichen Dank für die rasche und sinnige Antwort!!!

Viele Grüße
Marco


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:39 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