Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Blinking Cursor in Textbox

In a textbox, how can u prevent the display of the blinking cursor when you click on it?

I did read in some forums that there is call to a particular api but when i tried it in my code, an error was shown. Please provide the complete code for this purpose if possible and let me know if there is a particular event where the code should be executed.

This textbox is part of a form window that am creating for the simulation of a lan messenger. I am using C#. The form has two textboxes in order to resemble that of google talk. It would be desirable to prevent displaying the blinking cursor on the upper textbox.

I tried:

[DllImport("user32")] 
private static extern bool HideCaret(IntPtr hWnd); 
public void HideCaret() { HideCaret(TextBox1.Handle); } 

I get the error: "DllImport could not be found."

like image 887
Avik Avatar asked Mar 02 '09 04:03

Avik


1 Answers

If you want to disallow editing on the textbox, set it's ReadOnly property to true.

If you want to allow editing but still hide the caret, call the Win32 API exactly as specified:

[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool HideCaret(IntPtr hWnd);

...

HideCaret(myTextBox.Handle);
like image 179
Judah Gabriel Himango Avatar answered Oct 19 '22 08:10

Judah Gabriel Himango