CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2009
    Posts
    19

    Question How To Get Rid of SetFocus on TextBoxes

    Hi VB gurus,
    Need some help here...Doing an application with VB6 that uses textboxes and click actions...How do I get rid of the SetFocus which appears in the textboxes during run-time. TQ.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: How To Get Rid of SetFocus on TextBoxes

    Set the TabStop property of the TextBox to False, in Design Time

    By the way, welcome to the Forums!

  3. #3
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: How To Get Rid of SetFocus on TextBoxes

    You can also achieve this by keeping all the text boxes in a frame and disable the frame during form load or design.
    Once form is active and when required you can enable the Frame. Still if you click on textbox cursor enters the textbox and will get the focus. If you are avoiding the user to make changes in the textboxes but you want them to click, you can use locked property of textbox to make readonly.
    Last edited by ComITSolutions; August 6th, 2009 at 05:30 AM.
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

  4. #4
    Join Date
    Aug 2009
    Posts
    19

    Re: How To Get Rid of SetFocus on TextBoxes

    Quote Originally Posted by HanneSThEGreaT View Post
    Set the TabStop property of the TextBox to False, in Design Time

    By the way, welcome to the Forums!
    Thanks for the tips However, cursor still appears in TextBox during runtime.

  5. #5
    Join Date
    Aug 2009
    Posts
    19

    Re: How To Get Rid of SetFocus on TextBoxes

    Quote Originally Posted by ComITSolutions View Post
    You can also achieve this by keeping all the text boxes in a frame and disable the frame during form load or design.
    Once form is active and when required you can enable the Frame. Still if you click on textbox cursor enters the textbox and will get the focus. If you are avoiding the user to make changes in the textboxes but you want them to click, you can use locked property of textbox to make readonly.
    Thanks for the info But the cursor still enters the textbox. Any possible way to hide the focus?

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How To Get Rid of SetFocus on TextBoxes

    In the SetFocus() event, just move the cursor to the next valid cursor. Otherwise, if the .TabStop is set to FALSE, the user will tab by it.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: How To Get Rid of SetFocus on TextBoxes

    Quote Originally Posted by VirtualBaby View Post
    Thanks for the info But the cursor still enters the textbox. Any possible way to hide the focus?
    In post #3 I have mentioned that if mouse is clicked on textbox focus will go the text box, read the post clearly.

    1) If Foucus is not needed why are using Textbox? you can use labels and fool the user by Setting backcolor property to &H8000000E (white) and BorderStyle Property to 1 that is fixed single.
    You can code for lable's click event.
    2) If you still persists using textbox and it should not be focused then make its enabled property false, but you will not be able to raise mouse click event.

    3) What are you trying to do in your program? If you explain in detail, there are many gurus in this forum will guide you in the right direction.
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: How To Get Rid of SetFocus on TextBoxes

    You could also use the TextBox's GotFocus event to redirect the focus to another control.
    This whole concept of yours basically defeats the purpose of having a TextBox there in the first place. Why do you want a textBox which is "unfocusable" ¿

  9. #9
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: How To Get Rid of SetFocus on TextBoxes

    Quote Originally Posted by HanneSThEGreaT View Post
    You could also use the TextBox's GotFocus event to redirect the focus to another control.
    This whole concept of yours basically defeats the purpose of having a TextBox there in the first place. Why do you want a textBox which is "unfocusable" ¿
    I feel the same way !
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

  10. #10
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: How To Get Rid of SetFocus on TextBoxes

    One might want to use a textbox because of its abilty to have scrollbars and multiline and wordwrap.
    I had a similar situation once, so what I did was:
    I put a dummy textbox named txtTrap outside the visible range of the form.
    Then in the _GotFocus() event of the TextBox where I did not want a focus I put:
    txtTrap.SetFocus()
    So whenever this window gets the focus it passes it on to an invisible field.

  11. #11
    Join Date
    Oct 2006
    Posts
    327

    Re: How To Get Rid of SetFocus on TextBoxes

    Hello,

    Assuming Text1 is not the only control on the form, this will work whatever would be the Tabstop and the tabindex properties of text1 :

    Code:
    Private Sub Text1_GotFocus()
     Text1.Enabled = False
    End Sub
    
    Private Sub Text1_LostFocus()
      Text1.Enabled = True
    End Sub
    And so, the scrollbars would work too...

  12. #12
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: How To Get Rid of SetFocus on TextBoxes

    Quote Originally Posted by WoF View Post
    One might want to use a textbox because of its abilty to have scrollbars and multiline and wordwrap.
    I had a similar situation once, so what I did was:
    I put a dummy textbox named txtTrap outside the visible range of the form.
    Then in the _GotFocus() event of the TextBox where I did not want a focus I put:
    txtTrap.SetFocus()
    So whenever this window gets the focus it passes it on to an invisible field.
    Good One WoF!!
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

  13. #13
    Join Date
    Aug 2009
    Posts
    19

    Smile Re: How To Get Rid of SetFocus on TextBoxes

    Quote Originally Posted by WoF View Post
    One might want to use a textbox because of its abilty to have scrollbars and multiline and wordwrap.
    I had a similar situation once, so what I did was:
    I put a dummy textbox named txtTrap outside the visible range of the form.
    Then in the _GotFocus() event of the TextBox where I did not want a focus I put:
    txtTrap.SetFocus()
    So whenever this window gets the focus it passes it on to an invisible field.
    Thanks a lot all VB gurus
    I'm still new at VB6. Im just trying to code an Image Shuffle 15 like game.
    Yes, Label1.Caption is another option instead of Text1.text
    Creating an invisible dummy textbox is a wise solution. TQ.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured