Windows Forms: How to make a thick blinking cursor in a textbox?

I am rewriting a Windows Forms Application (updated structure, rewritten logic, etc.) and there is one thing I just cannot figure out how they did it. The text boxes in the original app had a thick flickering cursor: http://screencast.com/t/8QYUcjuh3n

In my life I cannot figure out how to do this. Please, help?

0


a source to share


1 answer


You can do this with pinvoke CreateCaret

The example uses Winform with a button (button1) and a textbox (textBox1).

Add this with the directive:

using System.Runtime.InteropServices;

      

Add these ads:



[DllImport("user32.dll")]
static extern bool CreateCaret(IntPtr hWnd, IntPtr hBitmap, int nWidth, int nHeight);
[DllImport("user32.dll")]
static extern bool ShowCaret(IntPtr hWnd);  

      

Add this code to the button click event:

  // Thickness is set where I have 10.
  CreateCaret(textBox1.Handle, IntPtr.Zero, 10, textBox1.Height);
  ShowCaret(textBox1.Handle);

      

When you press the button, you get a thicker cursor.

It also discusses this here .

+1


a source







All Articles