Autor Beitrag
kostonstyle
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 94



BeitragVerfasst: Di 19.01.10 14:34 
hallo miteinander
wie kann ich das Textbox definieren, dass nur Integer Werte eingeben kann bis 1000 und keine negative Zahlen.

Thx kostonstyle
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Di 19.01.10 14:54 
Hallo,


warum nimmst du kein NumericUpDown-UserControl?

Ups, WPF ... ich hab ein NumericUpDown WPF Control gemacht. Kann ich dir bei Bedarf schicken. Ansonsten siehe Jürgens Beitrag.

Gruß Daniel


Zuletzt bearbeitet von danielf am Di 19.01.10 15:17, insgesamt 1-mal bearbeitet
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Di 19.01.10 15:07 
Gibt es die MaskedTextBox für WPF? Die wäre je nach Zweck vielleicht besser geeignet. Jürgen
kostonstyle Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 94



BeitragVerfasst: Di 19.01.10 16:47 
dann werde ich es mal versuchen. Habe noch eine Frage zu TextBox, und zwar möchte an Textbox ein int wert zuweisen, aber leider erhalte die Fehlermeldung, dass der Textbox nur String werte annehmen.
ausblenden C#-Quelltext
1:
this.txt_plu.Text = plu_cl.file_selected();					

was kann ich tun?

danke kostonstyle
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 19.01.10 16:58 
user profile iconkostonstyle hat folgendes geschrieben Zum zitierten Posting springen:
dann werde ich es mal versuchen. Habe noch eine Frage zu TextBox, und zwar möchte an Textbox ein int wert zuweisen, aber leider erhalte die Fehlermeldung, dass der Textbox nur String werte annehmen.
Eine Zahl musst du zuerst in einen String umwandeln. Es sollte reichen Integerwert.ToString() zu benutzen.

user profile icondanielf hat folgendes geschrieben Zum zitierten Posting springen:
Ups, WPF ... ich hab ein NumericUpDown WPF Control gemacht. Kann ich dir bei Bedarf schicken.
Da schau doch einmal in dieses Thema:
www.c-sharp-forum.de/viewtopic.php?t=97257
Ich glaube da wirst du einen weiteren Interessenten finden. ;-)
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Di 19.01.10 17:10 
Ich habe das Control an kostonstyle geschickt. Wenn es "funktioniert" werde ich es hier an den Thread dran hängen.
kostonstyle Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 94



BeitragVerfasst: Mi 20.01.10 11:33 
habe im Internet nach MaskedTextBox gesucht, aber leider nichts gebräuchliches gefunden. Habe mir überlegt, es gibt für TextBox KeyDown Event.
ausblenden C#-Quelltext
1:
private void txt_pos_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)					

Dort kann ich ja überprüfen, ob Zahlen oder Buchstaben eingegeben wurde und dementsprechend e.Handle auf True setzen. Aber leider kenne ich keine Funktion, dass überprüft, ob Zahlen oder Buchstaben eingetippt wurde.
Im Internet habe ich folgedes für WinForms gefunden
ausblenden C#-Quelltext
1:
2:
3:
4:
if (!char.IsDigit(e.Key) && !char.IsControl(e.Key))
            {
                
            }

Funktioniert aber nicht für WPF.

Danke kostonstyle
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Mi 20.01.10 12:32 
Das funktioniert nicht, weil das Event KeyDown in WPF andere Parameter als in WinForms übergibt.

Verwende für deine TextBox das PreviewTextInput-Event. Dann kannst du den TextInput vorhab überprüfen:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
        private void textBox1_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            foreach (var item in e.Text)
            {
                e.Handled = !char.IsDigit(item);
            }
        }


Allerdings hilft das nicht gegen Paste Überwachung :( Hab aber grade auch nichts sinnvolles gefunden, vlt. kann ja jemand anderes helfen :/ :nixweiss:

// Edit: Das macht wohl in der Schleife mehr Sinn
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
if (!char.IsDigit(item))

    e.Handled = true;
    return;
}


Zuletzt bearbeitet von danielf am Mi 20.01.10 18:39, insgesamt 1-mal bearbeitet
kostonstyle Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 94



BeitragVerfasst: Mi 20.01.10 15:42 
Habe es so gelöst..
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
private void txt_pos_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            this.txt_pos.Background = Brushes.LightSeaGreen;
            if ((e.Key < Key.D0 || e.Key > Key.D9) &&
                (e.Key < Key.NumPad0 || e.Key > Key.NumPad9))
            {
                e.Handled = true;
            }
        }
Nemag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 132
Erhaltene Danke: 2



BeitragVerfasst: Mi 20.01.10 16:44 
Wie Daniel schon schrieb: Was passiert denn bei den gängigen: "Copy und Paste?" Varianten?
;-)