Autor Beitrag
erfahrener Neuling
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 233
Erhaltene Danke: 19

Win 7, Win 10
C#, ASP-MVC (VS 2017 Community), MS SQL, Firebird SQL
BeitragVerfasst: Mo 06.06.16 09:12 
Hallo,

ist es möglich, zu verhindern, dass ein ungewünschtes Zeichen im PreviewKeyDown-Event hinzugefügt wird? Also nur Zahlen zB zulassen und andere Zeichen gar nicht erst dem TextBox.Text hinzufügen.

Gruß Julian
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4798
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 06.06.16 09:32 
Ja, genau dafür ist ja dieses Ereignis. ;-)
Setze einfach für die nicht gewollten Zeichen
ausblenden C#-Quelltext
1:
e.Handled = true;					

Für diesen Beitrag haben gedankt: erfahrener Neuling
erfahrener Neuling Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 233
Erhaltene Danke: 19

Win 7, Win 10
C#, ASP-MVC (VS 2017 Community), MS SQL, Firebird SQL
BeitragVerfasst: Mo 06.06.16 09:40 
Hi Th69

Welche e's meinst du? Bei mir haben die PreviewKeyDownEventArgs kein .Handled.

EDIT: Ok ich hab's jetzt doch mit dem KeyPressed-Event gemacht. Dort hab ich erst das falsche Zeichen immer per Substring rausgemacht, besser funktioniert aber e.Handled = true
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mo 06.06.16 11:14 
Copy&Paste nicht vergessen ;)
erfahrener Neuling Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 233
Erhaltene Danke: 19

Win 7, Win 10
C#, ASP-MVC (VS 2017 Community), MS SQL, Firebird SQL
BeitragVerfasst: Mo 06.06.16 11:28 
user profile iconRalf Jansen hat folgendes geschrieben Zum zitierten Posting springen:
Copy&Paste nicht vergessen ;)
Was meinst du?
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mo 06.06.16 11:36 
Paste mal eine Zahl die du in der Zwischenablage hast per Strg+V in die TextBox und prüfe ob dein Code zieht.

Für diesen Beitrag haben gedankt: erfahrener Neuling
erfahrener Neuling Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 233
Erhaltene Danke: 19

Win 7, Win 10
C#, ASP-MVC (VS 2017 Community), MS SQL, Firebird SQL
BeitragVerfasst: Mo 06.06.16 12:02 
Oh danke, daran hatte ich gar nicht gedacht.

Hab's jetzt die STRG+V-Erkennung eingefügt. Kann ich dann im gleichen Atemzug noch herausfinden, was ich denn einfügen will, um nicht gewünschte Zeichen zu entfernen? Würde das ungern über's TextChanged-Event machen.

EDIT: ist gelöst. Wen's interessiert: Clipboard.GetText()