How to read in text from a textbox
-
Hi, I've been looking for like 2 hours for a method or anything that reads the text which is typed in a textbox. I don't really know much about buttons and textfields. I usually work with the console. Can anyone tell me how to read in text from a textbox plz? Thanks in advance!
hi textBox1.text will give you the text is typed in textBox1:)
Tamimi - Code
-
hi textBox1.text will give you the text is typed in textBox1:)
Tamimi - Code
Hi Tamimi, That worked! Thank you! I declared readIn to read what is typed in the textbox like this: string readIn = this.texBox1.Text; And attaching it to the eventhandler like this: readIn += new KeyEventHandler(texBox1_KeyPress); It gives me the error: No overload for 'texBox1_KeyPress' matches delegate 'System.Windows.Forms.KeyEventHandler' What am i doing wrong?
-
Hi Tamimi, That worked! Thank you! I declared readIn to read what is typed in the textbox like this: string readIn = this.texBox1.Text; And attaching it to the eventhandler like this: readIn += new KeyEventHandler(texBox1_KeyPress); It gives me the error: No overload for 'texBox1_KeyPress' matches delegate 'System.Windows.Forms.KeyEventHandler' What am i doing wrong?
hi could you give more details about what you are trying to do ?? if simply you want the text in a textbox the .Text property its enough and no need to attaching anything. what exactly you want to do ??
Tamimi - Code
-
hi could you give more details about what you are trying to do ?? if simply you want the text in a textbox the .Text property its enough and no need to attaching anything. what exactly you want to do ??
Tamimi - Code
-
Hi, I want to accept only 0, 1, 2 .... 9 as input. In order to do this, i have to attach texbBox1.Text to the keypressed handler. But i got it fixed now, Thank you!
hi is there any wrong with this: private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { int intKeyValue = (int)e.KeyChar; if (((intKeyValue<48 || intKeyValue>57 ) && intKeyValue!=46)) { e.Handled = true; } }
Tamimi - Code
-
Hi, I want to accept only 0, 1, 2 .... 9 as input. In order to do this, i have to attach texbBox1.Text to the keypressed handler. But i got it fixed now, Thank you!
-
hi is there any wrong with this: private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { int intKeyValue = (int)e.KeyChar; if (((intKeyValue<48 || intKeyValue>57 ) && intKeyValue!=46)) { e.Handled = true; } }
Tamimi - Code
-
Hi Tamimi, There is nothing wrong with that method. In fact, thats the eventhandler i was trying to attach 'readIn' to. If a key is pressed 'readIn' will call that eventhandler to check if its a valid one. Sorry for the confusion Tamimi!
hi are you trying to do this: this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress); if not feel free to ask again
Tamimi - Code
-
hi are you trying to do this: this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress); if not feel free to ask again
Tamimi - Code
Hi Tamimi, Thats exactly what i meant. But i fixed that half an hour ago :) I do have another question... If i want to get everything between 2 chars, how would i do that? Example: [1] [12] [123] How would i get everything between the '[ ]' chars? Substring wont help, coz the characters inside the [] can be sometimes 1, 3 or more. Thanks in advance!
-
Hi Tamimi, Thats exactly what i meant. But i fixed that half an hour ago :) I do have another question... If i want to get everything between 2 chars, how would i do that? Example: [1] [12] [123] How would i get everything between the '[ ]' chars? Substring wont help, coz the characters inside the [] can be sometimes 1, 3 or more. Thanks in advance!
hi try this: int intStartIndex = textBox1.Text.IndexOf("[") + 1; int intEndIndex = textBox1.Text.IndexOf("]") - 1; string strBetween = textBox1.Text.Substring(intStartIndex,intEndIndex); but you should be sure that the chars "[" and "]" are exists if not you will get an error index or something like this
Tamimi - Code
-
hi try this: int intStartIndex = textBox1.Text.IndexOf("[") + 1; int intEndIndex = textBox1.Text.IndexOf("]") - 1; string strBetween = textBox1.Text.Substring(intStartIndex,intEndIndex); but you should be sure that the chars "[" and "]" are exists if not you will get an error index or something like this
Tamimi - Code
-
you are welcome:)
Tamimi - Code