Others have stated that setting "ReadOnly" to "True" will avoid the caret
when you click on a textbox. They are mistaken there.
I am using VB.Net but maybe my sample code below might provide a simpler
answer.
It involves creating a new class (MyTextBox) with the added property of
"NoCaret" which defaults to "False" (i.e. it shows caret by default).
Add the following code to your project in a new class module, rebuild the project, then drag your new textbox (then found at top of your Toolbox) onto your form. To stop the caret showing tick "NoCaret" in the properties panel for each MyTextbox control you add to your forms.
So, you start by creating a new Class Module as follows (drawing the textbox in the designer is not necessary. It is actually better NOT to draw it since that will create unnecessary "InitializeComponent" code that will just muddy the waters. The line "MyBase.New()" in the sub "New()" takes care of everything)
Imports System.Runtime.InteropServices
Public Class MyTextBox
Inherits TextBox
Private Declare Function HideCaret Lib "user32.dll" (ByVal hwnd As Int32) As Int32
Private Declare Function ShowCaret Lib "user32.dll" (ByVal hwnd As Int32) As Int32
Private _HideCaret As Boolean
Public Sub New()
MyBase.New()
End Sub
Public Property NoCaret As Boolean
Get
Return _HideCaret
End Get
Set(ByVal value As Boolean)
_HideCaret = value
End Set
End Property
Private Sub TextBox_MouseMove(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.MouseMove
If Me.NoCaret = True Then
HideCaret(Handle.ToInt32)
Else
ShowCaret(Handle.ToInt32)
End If
End Sub
End Class
Make sure, though, that any EXISTING code that is making a "TypeOf" test on any existing textboxes on your form such as:
For each tb as control in MyForm.Controls
if TypeOf tb Is TextBox then
.....{do something}
endif
Next
is changed to:
For each tb as control in MyForm.Controls
if TypeOf tb.Parent Is TextBox then
.....{do something}
endif
Next