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. Cursor Position

Cursor Position

Scheduled Pinned Locked Moved C#
helptutorialquestion
6 Posts 4 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.
  • C Offline
    C Offline
    chettu
    wrote on last edited by
    #1

    Hi Is it possible to identify the Cursor postion inside the textbox not the mouse pointer.If so how to access that?? Plz Help Regards Deepak.S

    S M N 3 Replies Last reply
    0
    • C chettu

      Hi Is it possible to identify the Cursor postion inside the textbox not the mouse pointer.If so how to access that?? Plz Help Regards Deepak.S

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      TextBox.SelectionStart might be what you're looking for. Regards, mav

      1 Reply Last reply
      0
      • C chettu

        Hi Is it possible to identify the Cursor postion inside the textbox not the mouse pointer.If so how to access that?? Plz Help Regards Deepak.S

        S Offline
        S Offline
        Stefan Troschuetz
        wrote on last edited by
        #3

        I think you can get this information through evaluation of SelectionStart, SelectionLength and SelectedText properties. MSDN states that if no text is selected in the control, the SelectionStart property indicates the insertion point for new text i.e. the current cursor position. If otherwise something is selected, the cursor position should be the sum of SelectionStart and SelectionLength.

        int cursorPos;
        if (textbox.SelectedText == string.Empty)
        cursorPos = textbox.SelectionStart;
        else
        cursorPos = textbox.SelectionStart + textbox.SelectionLength;

        P.S: All information bases on research in MSDN topics, so the above code snippet isn't tested and comes without warranty :)


        www.troschuetz.de

        C 1 Reply Last reply
        0
        • S Stefan Troschuetz

          I think you can get this information through evaluation of SelectionStart, SelectionLength and SelectedText properties. MSDN states that if no text is selected in the control, the SelectionStart property indicates the insertion point for new text i.e. the current cursor position. If otherwise something is selected, the cursor position should be the sum of SelectionStart and SelectionLength.

          int cursorPos;
          if (textbox.SelectedText == string.Empty)
          cursorPos = textbox.SelectionStart;
          else
          cursorPos = textbox.SelectionStart + textbox.SelectionLength;

          P.S: All information bases on research in MSDN topics, so the above code snippet isn't tested and comes without warranty :)


          www.troschuetz.de

          C Offline
          C Offline
          chettu
          wrote on last edited by
          #4

          Hi That did the job.. but i want to know is it possible to position (move the cursor where i want to move) the cursor inside the textbox thru code. Regards Deepak.S

          S 1 Reply Last reply
          0
          • C chettu

            Hi That did the job.. but i want to know is it possible to position (move the cursor where i want to move) the cursor inside the textbox thru code. Regards Deepak.S

            S Offline
            S Offline
            Stefan Troschuetz
            wrote on last edited by
            #5

            It's all in the docs: MSDN topic of SelectionStart states: "You can programmatically move the caret within the text box by setting the SelectionStart to the position within the text box where you want the caret to move to and set the SelectionLength property to a value of zero (0). The text box must have focus in order for the caret to be moved."


            www.troschuetz.de

            1 Reply Last reply
            0
            • C chettu

              Hi Is it possible to identify the Cursor postion inside the textbox not the mouse pointer.If so how to access that?? Plz Help Regards Deepak.S

              N Offline
              N Offline
              NassosReyzidis
              wrote on last edited by
              #6

              System.Windows.Forms.Form.MousePosition so from inside the form code : MousePosition GanDad

              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