Winform how the flashing cursor is removed TextBox

method one

Enable the property of the TextBox Falseto

TextBox1.Enable = False;	//或者在属性窗口直接设置

This method has a drawback, is that if you are a multi-line TextBox, you can not browse the slide
Here Insert Picture Description

Method Two

We can consider listening TextBox, once they come into a focus, we changed directly to other controls, above figure as an example, I named two TextBox Txt_Infoand Txt_Senderdouble-click the TextBox writing Enterevent

private void Txt_Info_Enter(object sender, EventArgs e)
{
    Txt_Sender.Focus();				//将焦点定位到其他控件
}

Of course, you can modify the code designer

this.Txt_Info.Enter += (s,e) => Txt_Sender.Focus();

Method Three

Using the API set, enter the MouseDownevent

[DllImport("user32",EntryPoint = "HideCaret")]
private static extern bool HideCaret(IntPtr hWnd);            //需引入命名空间using System.Runtime.InteropServices;

private void Txt_RecInfo_MouseDown(object sender, MouseEventArgs e)
{
    HideCaret((sender as TextBox).Handle);
}
Published 62 original articles · won praise 68 · views 160 000 +

Guess you like

Origin blog.csdn.net/ZUFE_ZXh/article/details/103856913