Reputation: 2077
I am making a program in VB.NET and need to hide the Caret in textboxes.
I could live with it being either completely hidden or just the same colour as the textboxes background colour. How can I go about doing this? I would prefer to stay away from Custom Controls if at all possible.
Thank you
Upvotes: 1
Views: 2547
Reputation: 942099
Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.
Public Class NoCaretBox
Inherits TextBox
Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
HideCaret(Me.Handle)
MyBase.OnGotFocus(e)
End Sub
Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
ShowCaret(Me.Handle)
MyBase.OnLostFocus(e)
End Sub
Private Declare Function HideCaret Lib "user32.dll" (ByVal hWnd As IntPtr) As Boolean
Private Declare Function ShowCaret Lib "user32.dll" (ByVal hWnd As IntPtr) As Boolean
End Class
Upvotes: 6