简体   繁体   English

避免文本框成为焦点

[英]Avoid a textbox get's focus

I'm working in a Windows Form Application, I have a textbox which I want to avoid that gets the focus. 我在Windows窗体应用程序中工作,我有一个文本框,我希望避免引起焦点。

Now I'm using the property Enable but it gives a bad appearance to the form. 现在,我使用了属性Enable,但是它使表单看起来很糟。

Also I tried with this 我也尝试过这个

private void txtMyTextbox_Enter(object sender, EventArgs e)
{
    ActiveControl = objMyOtherControl;
}

But like I'm selecting words of that textbox when the event is raise the textbox lose the selection. 但是就像我在事件引发时选择该文本框的单词一样,文本框会丢失选择。

If you want to make the textbox unfocusable but you still want be able to select the text, what you are looking for is the ReadOnly property. 如果要使文本框无法集中显示,但仍希望能够选择文本,则要查找的是ReadOnly属性。


Here is an extract from the official DOC: 以下是官方DOC的摘录:

You can transform an editable Windows Forms text box into a read-only control. 您可以将可编辑的Windows窗体文本框转换为只读控件。 For example, the text box may display a value that is usually edited but may not be currently, due to the state of the application. 例如,由于应用程序的状态,文本框可能会显示一个通常被编辑但当前可能不是的值。

To create a read-only text box 创建只读文本框

Set the TextBox control's ReadOnly property to true. 将TextBox控件的ReadOnly属性设置为true。 With the property set to true, users can still scroll and highlight text in a text box without allowing changes. 将属性设置为true时,用户仍可以滚动并突出显示文本框中的文本,而无需进行更改。 A Copy command is functional in a text box, but Cut and Paste commands are not. 复制命令在文本框中有效,但剪切和粘贴命令无效。
Note The ReadOnly property only affects user interaction at run time . 注意ReadOnly属性仅影响运行时的用户交互 You can still change text box contents programmatically at run time by changing the Text property of the text box. 您仍然可以在运行时通过更改文本框的Text属性以编程方式更改文本框内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM