method one
Enable the property of the TextBox False
to
TextBox1.Enable = False; //或者在属性窗口直接设置
This method has a drawback, is that if you are a multi-line TextBox, you can not browse the slide
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_Info
and Txt_Sender
double-click the TextBox writing Enter
event
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 MouseDown
event
[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);
}