Gerald Loreto
Gerald Loreto

Reputation: 23

Disable iBeam pointer in TextBox using VB.NET

I am currently working on a TextBox using VB.NET 2015 that is read-only and only inserts characters by a button click event. I want to hide or disable the iBeam inside the TextBox to let the user know that it is only accessible by the button click and not by manual typing on the actual keyboard. I have tried changing its ReadOnly property to True and cursor property to cursors other than the iBeam but they don't seem to work.

Is there another way, may it be a code or a property that disables the iBeam in the TextBox when its accessed?

This image is my example of an on-screen keyboard. As you can see, the iBeam on the TextBox is visible as soon as I click on one of the on-screen keys.

enter image description here

Upvotes: 0

Views: 2370

Answers (1)

Idle_Mind
Idle_Mind

Reputation: 39122

Use the HideCaret() API call from the GotFocus() event of your TextBox:

Private Declare Function HideCaret Lib "user32.dll" (ByVal hWnd As IntPtr) As Boolean

Private Sub TextBox1_GotFocus(sender As Object, e As EventArgs) Handles TextBox1.GotFocus
    HideCaret(TextBox1.Handle)
End Sub

Upvotes: 2

Related Questions