Results 1 to 9 of 9

Thread: [RESOLVED] Can A "Unique" Caret Be Global On A Form?

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    44

    Resolved [RESOLVED] Can A "Unique" Caret Be Global On A Form?

    Previously I had asked for help in creating a "unique" caret, etc... The suggestions from Numtel worked GREAT for us.... http://www.vbforums.com/showthread.php?t=403463

    However, now I am wondering if there is a way to make the unique caret "global" for the whole form?

    We are currently coding every single text box that we want the unique caret to show up in. It's working just fine and it's not THAT hard to do, but some of our forms have A LOT of text boxes. So I was just wondering if it's possible to make the unique caret we create global for the whole form, or do we have to code each box?

    Thanks again for everyones help.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Can A "Unique" Caret Be Global On A Form?

    well never dealt with them

    looking at Numtel's answer.. it seems the Caret needs to be created / destroyed in each?? if thats the case.. then best u could do would be create a sub and call it in each gotfocus etc...

    hmmmm
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Can A "Unique" Caret Be Global On A Form?

    well.. to make it a bit simpler... use an array of textboxes.. then u dont have to code all of them?

    VB Code:
    1. Private Declare Function CreateCaret Lib "user32" (ByVal hwnd As Long, ByVal hBitmap As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    2. Private Declare Function ShowCaret Lib "user32" (ByVal hwnd As Long) As Long
    3. Private Declare Function DestroyCaret Lib "user32" () As Long
    4.  
    5.  
    6.  
    7.  
    8. Private Sub Text1_GotFocus(Index As Integer)
    9.     DestroyCaret
    10.     CreateCaret Text1(Index).hwnd, 0, 8, 14
    11.     ShowCaret Text1(Index).hwnd
    12. End Sub
    13.  
    14. Private Sub Text1_LostFocus(Index As Integer)
    15.     DestroyCaret
    16. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Can A "Unique" Caret Be Global On A Form?

    with statics code, if you have textboxes with different names, then you could put it into a sub and then call the sub by referencing the name of the textbox.

    VB Code:
    1. Private Declare Function CreateCaret Lib "user32" (ByVal hwnd As Long, ByVal hBitmap As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    2. Private Declare Function ShowCaret Lib "user32" (ByVal hwnd As Long) As Long
    3. Private Declare Function DestroyCaret Lib "user32" () As Long
    4.  
    5. Private Sub TBGotFocus(txtbox As TextBox)
    6.     With txtbox
    7.         DestroyCaret
    8.         CreateCaret .hwnd, 0, 8, 14
    9.         ShowCaret .hwnd
    10.     End With
    11. End Sub
    VB Code:
    1. Then in the GotFocus, have:
    2. TBGotFocus txtboxname.text
    Then in the LostFocus have:
    VB Code:
    1. Private Sub Text1_LostFocus()
    2.     DestroyCaret
    3. End Sub
    Wouldnt that work?

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    44

    Re: Can A "Unique" Caret Be Global On A Form?

    Yeah, we also tried that. So, I guess the answer to my question is "no"? lol

    Thanks for everyones help.

  6. #6
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Can A "Unique" Caret Be Global On A Form?

    Quote Originally Posted by bjmarler
    Yeah, we also tried that. So, I guess the answer to my question is "no"? lol

    Thanks for everyones help.
    there is always a way to do something in vb. just have to find it.

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Can A "Unique" Caret Be Global On A Form?

    You could use a timer set to 1:
    VB Code:
    1. Private Sub Timer1_Timer()
    2.     Static ctl As Control
    3.     If Not ctl Is ActiveControl Then
    4.         If TypeOf ActiveControl Is TextBox Then
    5.             If Not ctl Is Nothing Then DestroyCaret
    6.             CreateCaret ActiveControl.hwnd, 0, 8, 14
    7.             ShowCaret ActiveControl.hwnd
    8.         Else
    9.             If Not ctl Is Nothing Then DestroyCaret
    10.         End If
    11.         Set ctl = ActiveControl
    12.     End If
    13. End Sub

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    44

    Re: Can A "Unique" Caret Be Global On A Form?

    Cool Beans!!! Thanks. I'll give it a try.

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    44

    Re: Can A "Unique" Caret Be Global On A Form?

    Ok. Sorry this took me so long, but I was away from the office for a few days.

    IT WORKS!!! Woo-Hoo. Thank you so much BushMobile. All of you on this forum are GREAT! Thanks again.

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