Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Textbox Pin
Michael_Davies9-Dec-16 7:03
Michael_Davies9-Dec-16 7:03 
GeneralRe: C# Textbox Pin
Pavlex49-Dec-16 7:06
Pavlex49-Dec-16 7:06 
GeneralRe: C# Textbox Pin
Michael_Davies9-Dec-16 7:29
Michael_Davies9-Dec-16 7:29 
GeneralRe: C# Textbox Pin
Pavlex49-Dec-16 7:41
Pavlex49-Dec-16 7:41 
GeneralRe: C# Textbox Pin
Eddy Vluggen9-Dec-16 8:01
professionalEddy Vluggen9-Dec-16 8:01 
GeneralRe: C# Textbox Pin
Michael_Davies9-Dec-16 8:23
Michael_Davies9-Dec-16 8:23 
AnswerRe: C# Textbox Pin
Gerry Schmitz9-Dec-16 8:26
mveGerry Schmitz9-Dec-16 8:26 
AnswerRe: C# Textbox Pin
OriginalGriff9-Dec-16 8:27
mveOriginalGriff9-Dec-16 8:27 
When you write a KeyPress handler for the TextBox, you get two parameters:
C#
private void myTextBox_KeyPress(object sender, KeyPressEventArgs e)

sender is the text box that generate the event.
e is the information on the key press.
This information includes the key pressed:
C#
char keyPressedByUser = e.KeyChar;
And Handled which is a bool which the TextBox looks at when you are finished to decide if it should treat the key as input or not. If you set it to true the Textbox will ignore the user input. If you leave it at false the TextBox will insert the character to the textbox.
You also have the Text property of the TextBox which means you can get the data currently in it.

From that and your labels, you should be able to work out how to restrict the user input just as you wanted.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

GeneralRe: C# Textbox Pin
Pavlex49-Dec-16 22:06
Pavlex49-Dec-16 22:06 
GeneralRe: C# Textbox Pin
OriginalGriff9-Dec-16 22:21
mveOriginalGriff9-Dec-16 22:21 
GeneralRe: C# Textbox Pin
Pavlex49-Dec-16 23:07
Pavlex49-Dec-16 23:07 
GeneralRe: C# Textbox Pin
OriginalGriff9-Dec-16 23:38
mveOriginalGriff9-Dec-16 23:38 
GeneralRe: C# Textbox Pin
Pavlex410-Dec-16 0:09
Pavlex410-Dec-16 0:09 
GeneralRe: C# Textbox Pin
OriginalGriff10-Dec-16 0:24
mveOriginalGriff10-Dec-16 0:24 
GeneralRe: C# Textbox Pin
Pavlex410-Dec-16 0:26
Pavlex410-Dec-16 0:26 
GeneralRe: C# Textbox Pin
OriginalGriff10-Dec-16 0:41
mveOriginalGriff10-Dec-16 0:41 
GeneralRe: C# Textbox Pin
Pavlex410-Dec-16 0:46
Pavlex410-Dec-16 0:46 
GeneralRe: C# Textbox Pin
OriginalGriff10-Dec-16 0:59
mveOriginalGriff10-Dec-16 0:59 
GeneralRe: C# Textbox Pin
Pavlex410-Dec-16 1:08
Pavlex410-Dec-16 1:08 
GeneralRe: C# Textbox Pin
OriginalGriff10-Dec-16 1:12
mveOriginalGriff10-Dec-16 1:12 
GeneralRe: C# Textbox Pin
Pavlex410-Dec-16 1:22
Pavlex410-Dec-16 1:22 
GeneralRe: C# Textbox Pin
OriginalGriff10-Dec-16 1:44
mveOriginalGriff10-Dec-16 1:44 
QuestionNew to c# Pin
Member 19561089-Dec-16 4:14
Member 19561089-Dec-16 4:14 
AnswerRe: New to c# Pin
ZurdoDev9-Dec-16 4:54
professionalZurdoDev9-Dec-16 4:54 
AnswerRe: New to c# Pin
ZurdoDev9-Dec-16 4:55
professionalZurdoDev9-Dec-16 4:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.