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. .NET (Core and Framework)
  4. Select text in TextBox when Form loads

Select text in TextBox when Form loads

Scheduled Pinned Locked Moved .NET (Core and Framework)
question
2 Posts 1 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.
  • R Offline
    R Offline
    ricecake
    wrote on last edited by
    #1

    How do I have a form appear with the text in a TextBox selected? I have a simple dialog window that has a single textbox for user input and two buttons (OK and Cancel). When the dialog window loads, I would like the text in the TextBox to be selected so that the user can start typing as soon as the window comes up, instead of having to manually click on (or tab to) the textbox. I have tried placing the following line: textbox_sleep_time_ms->Select(0, textbox_sleep_time_ms->Text->Length); both as the last statement in the constructor for the form, and as the only statement in the form's Load event handler, but neither one will select the text. I don't know if it's relevant, but I have set the default button for the form to the OK button so that the user can just press Enter to accept the value. -- Marcus Kwok

    R 1 Reply Last reply
    0
    • R ricecake

      How do I have a form appear with the text in a TextBox selected? I have a simple dialog window that has a single textbox for user input and two buttons (OK and Cancel). When the dialog window loads, I would like the text in the TextBox to be selected so that the user can start typing as soon as the window comes up, instead of having to manually click on (or tab to) the textbox. I have tried placing the following line: textbox_sleep_time_ms->Select(0, textbox_sleep_time_ms->Text->Length); both as the last statement in the constructor for the form, and as the only statement in the form's Load event handler, but neither one will select the text. I don't know if it's relevant, but I have set the default button for the form to the OK button so that the user can just press Enter to accept the value. -- Marcus Kwok

      R Offline
      R Offline
      ricecake
      wrote on last edited by
      #2

      OK, I figured it out. I had to use textbox_sleep_time_ms->Select(); textbox_sleep_time_ms->SelectAll(); -- Marcus Kwok

      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