I have 2 text box in my form is it possible to show the blinking cursor in both text box when textbox1 is Focused
Printable View
I have 2 text box in my form is it possible to show the blinking cursor in both text box when textbox1 is Focused
No , i don't think this is possible. Blinking cursor only shows or display in the active textbox in the active form or application
I don't know if thats possible, you could fake a cursor, though it be a lot of work if you want to do it for a multiline textbox, heres a quick hack for a non-multiline textbox.
Code:' // Make Text1 blink a fake cursor when it loses focus. //
' Note: Form scalemode is Twips, Text1 is single-line, 3D, and uses same font properties as form!
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 500 ' blink rate
Timer1.Enabled = False
End Sub
Private Sub Text1_GotFocus()
Timer1.Enabled = False
PicCursor.Visible = False
End Sub
Private Sub Text1_LostFocus()
Timer1.Enabled = True
PicCursor.ZOrder 0
End Sub
Private Sub Timer1_Timer()
Dim CurT As Long, CurL As Long
CurL = 30 + Text1.Left + Me.TextWidth(Mid$(Text1.Text, 1, Text1.SelStart))
CurT = 30 + Text1.Top
PicCursor.Move CurL, CurT
PicCursor.Visible = Not PicCursor.Visible
End Sub
Thanks man great my blinking cursor instead of going to the next line it takes the text to the next line cursor stay at the tope
can we do some like
if keyascii = 13
then go to the next line
Not with that code. Play around with this and see if it helps.
Just a note, if text1 has scrollbars and it looses focus, then you scroll the textbox without setting focus on text1 then the fake blinking cursor will be in the wrong position. :( I think you would need to subclass text1 to get the scroll messages and act on those as well if you use this.Code:'// Make Text1 blink a fake cursor when it loses focus. //
' // Note: Form scalemode is Twips.//
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCaretPos Lib "user32" (lpPoint As POINTAPI) As Long
Dim XPos As Long
Dim YPos As Long
Private Sub Form_Load()
Timer1.Interval = 500 ' blink rate
Timer1.Enabled = False
End Sub
Private Sub Text1_LostFocus()
Dim CurT As Long, CurL As Long, OffSet3D As Long
' if tetxbox is 3D then add 30 twips
If Text1.Appearance = 1 Then OffSet3D = 30
' position pic box
CurL = Text1.Left + XPos + OffSet3D
CurT = Text1.Top + YPos + OffSet3D
PicCursor.Move CurL, CurT
Timer1.Enabled = True
PicCursor.ZOrder 0
End Sub
Private Sub Text1_GotFocus()
Timer1.Enabled = False
PicCursor.Visible = False
SaveCaretPos
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
SaveCaretPos
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
SaveCaretPos
End Sub
Private Sub Timer1_Timer()
' blink it
PicCursor.Visible = Not PicCursor.Visible
End Sub
Private Sub SaveCaretPos()
Dim pt As POINTAPI
' get caret pos. in text box
GetCaretPos pt
'Convert to twips
XPos = ScaleX(pt.X, vbPixels, vbTwips)
YPos = ScaleY(pt.Y, vbPixels, vbTwips)
End Sub
in my text box selstart set to 0 when I type from right to left ok but
When I press enter instead of the curse go to the next line text placed in next line and cursor stay at the top
op