none
cursor in textbox control

    Question

  • I need some help showing the cursor position in a text box on windows form.

     

     I’m using two buttons on a windows form to move a text insertion point to the left or right in a single line text box on the same form. The text insertion point does move left and right as commanded but I get no cursor in the text box to indicate where in the text box the insertion point is located.

     

    In VB 6 the cursor (flashing vertical bar) in the text box was shown at the txt1.SelStart location. The same does not seem to be true in VB .net when I use txt1.text.SelectionStart.

     

    I’ve tried everything I can think of to get the text cursor to show location.

     

    So, in VB .net how do I get the text box cursor to show up?

     

    Can anyone help?....   

     

    Cliffie

    Tuesday, June 20, 2006 3:01 AM

Answers

  • Actually the “TextBox1.Focused = True” doesn’t work. The .Focused property is a read only thing. So you can’t set it true or false. 

     

    However. In looking at that I found the related method “Txt1.Focus()” will switch the focus to the text box and I can finally see my caret/cursor.

     

    Thanks a lot gentleman. This discussion helped me a lot. This was my last problem to solve on this project. I can now deliver my first .net software to the customer on Monday.

     

    Cliffie

    Wednesday, June 21, 2006 1:46 AM

All replies

  • just a suggestion...because I was unable to duplicate your problem with the textbox...

     

    make usre your cursor property is set to a valid system cursor and the usewaitcursor property is set to false

    Tuesday, June 20, 2006 3:16 AM
    Moderator
  • Thanks for the quick reply..

    Yes. the CURSOR property is set to IBeam and the usewaitcursor is set FALSE. Still not cursor at the .SelectionStart location in the text box.

    Cliffie

     

    Tuesday, June 20, 2006 3:35 AM
  • You'd probably want to see the caret, not the cursor.  Just put the focus back on the textbox after you move the caret to make it visible again.

    Tuesday, June 20, 2006 3:43 PM
    Moderator
  • FYI....The cursor does not show in the textbox until it has focus
    Tuesday, June 20, 2006 4:35 PM
    Moderator
  • Ya.. You’re correct. In this case it’s called a Caret not a Cursor.

     

    So how do I get the focus back on the text box.  I can’t click on it because the system I’m working on has a touch screen (no mouse). I have to use touch screen buttons to move the caret in the text box.  In old VB6 I could get the focus on the text box by the .SetFocus method. I don’t see that in VB.net.

     

    I know these are dumb questions and really do appreciate the help.

     

    So how do I get the focus back on the text box (so I can see the caret/cursor) with no .SetFocus method on that control??

     

    Cliffie

    Tuesday, June 20, 2006 9:14 PM
  • Yeah, they changed that one.  Admittedly, the VB6 way was pretty miserable and a never ending source of exceptions.  Now it is TextBox1.Focused = True.
    Tuesday, June 20, 2006 9:29 PM
    Moderator
  • Actually the “TextBox1.Focused = True” doesn’t work. The .Focused property is a read only thing. So you can’t set it true or false. 

     

    However. In looking at that I found the related method “Txt1.Focus()” will switch the focus to the text box and I can finally see my caret/cursor.

     

    Thanks a lot gentleman. This discussion helped me a lot. This was my last problem to solve on this project. I can now deliver my first .net software to the customer on Monday.

     

    Cliffie

    Wednesday, June 21, 2006 1:46 AM