Multi Line TextBox for Addresses
-
I have a Multi Line Textbox. User will input address information.I wantta set cursor to new line, when user press enter key. I try following code to achive but it always set cursor to first line. what do u offer me :S protected sub txtAddress_KeyUp(........) handles txtaddress.keyup if (e.key= keys.enter){ txtaddress.text &= envoirenment.newline; } end sub
-
I have a Multi Line Textbox. User will input address information.I wantta set cursor to new line, when user press enter key. I try following code to achive but it always set cursor to first line. what do u offer me :S protected sub txtAddress_KeyUp(........) handles txtaddress.keyup if (e.key= keys.enter){ txtaddress.text &= envoirenment.newline; } end sub
Hi Greeky, Well the easy way is to set the AcceptsReturn property of the textbox to true. That should let them press enter onto new lines. If you want to do it manually, just change the code to the following (converted to c# from interesting vb hybrid)
protected void txtAddress_KeyUp(........) { if(e.key == keys.enter) { txtaddress.Text += environment.newline; txtaddress.SelectionStart = txtaddress.Text.Length-1; txtaddress.SelectionLength = 0; } } /* NB. This may not be quite right, as my VS is ill, so didnt test it */
The two lines to note are setting SelectionStart and SelectionLength. This just says move the cursor to the last character, and make sure no text is selected. Hope this helps Philip :-D -
Hi Greeky, Well the easy way is to set the AcceptsReturn property of the textbox to true. That should let them press enter onto new lines. If you want to do it manually, just change the code to the following (converted to c# from interesting vb hybrid)
protected void txtAddress_KeyUp(........) { if(e.key == keys.enter) { txtaddress.Text += environment.newline; txtaddress.SelectionStart = txtaddress.Text.Length-1; txtaddress.SelectionLength = 0; } } /* NB. This may not be quite right, as my VS is ill, so didnt test it */
The two lines to note are setting SelectionStart and SelectionLength. This just says move the cursor to the last character, and make sure no text is selected. Hope this helps Philip :-D