[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.
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
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:
Private Declare Function CreateCaret Lib "user32" (ByVal hwnd As Long, ByVal hBitmap As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function ShowCaret Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function DestroyCaret Lib "user32" () As Long
Private Sub Text1_GotFocus(Index As Integer)
DestroyCaret
CreateCaret Text1(Index).hwnd, 0, 8, 14
ShowCaret Text1(Index).hwnd
End Sub
Private Sub Text1_LostFocus(Index As Integer)
DestroyCaret
End Sub
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:
Private Declare Function CreateCaret Lib "user32" (ByVal hwnd As Long, ByVal hBitmap As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function ShowCaret Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function DestroyCaret Lib "user32" () As Long
Private Sub TBGotFocus(txtbox As TextBox)
With txtbox
DestroyCaret
CreateCaret .hwnd, 0, 8, 14
ShowCaret .hwnd
End With
End Sub
VB Code:
Then in the GotFocus, have:
TBGotFocus txtboxname.text
Then in the LostFocus have:
VB Code:
Private Sub Text1_LostFocus()
DestroyCaret
End Sub
Wouldnt that work?
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.
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.
Re: Can A "Unique" Caret Be Global On A Form?
You could use a timer set to 1:
VB Code:
Private Sub Timer1_Timer()
Static ctl As Control
If Not ctl Is ActiveControl Then
If TypeOf ActiveControl Is TextBox Then
If Not ctl Is Nothing Then DestroyCaret
CreateCaret ActiveControl.hwnd, 0, 8, 14
ShowCaret ActiveControl.hwnd
Else
If Not ctl Is Nothing Then DestroyCaret
End If
Set ctl = ActiveControl
End If
End Sub
Re: Can A "Unique" Caret Be Global On A Form?
Cool Beans!!! Thanks. I'll give it a try.
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.