Prevent Blinking Cursor in Textbox

后端 未结 7 1335
庸人自扰
庸人自扰 2020-12-09 22:33

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

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-09 23:05

    Hi, Try this code

    public class CustomTextBox:System.Windows.Forms.TextBox
    {
        [System.Runtime.InteropServices.DllImport("user32")]
        private static extern bool HideCaret(IntPtr hWnd);
    
        public CustomTextBox()
        {
            TabStop = false;
    
            MouseDown += new System.Windows.Forms.MouseEventHandler(CustomTextBox_MouseDown);
        }
    
        void CustomTextBox_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            HideCaret(this.Handle);
        }
    }
    

提交回复
热议问题