Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Multi Line TextBox for Addresses

Multi Line TextBox for Addresses

Scheduled Pinned Locked Moved C#
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Greeky
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • G Greeky

      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

      P Offline
      P Offline
      philip_cole
      wrote on last edited by
      #2

      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

      G 1 Reply Last reply
      0
      • P philip_cole

        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

        G Offline
        G Offline
        Greeky
        wrote on last edited by
        #3

        uehueh Thank you :D AcceptReturns is Ok. sometimes im stupid, why havent i checked all properties before ? :mad::confused: ;P Thank you again

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups