使文本框无法编辑

我想使一些 TextBoxes 在我的形式无法编辑,但我希望 text是明确的(黑色而不是灰色) ,这就是为什么我不想使用

myTextBox.Enabled = false;

不知怎么的,我希望它是残疾人,但与非灰色的前彩色。

有人知道吗?

172238 次浏览

Using the TextBox.ReadOnly property

TextBox.ReadOnly = true;

For a Non-Grey background you can change the TextBox.BackColor property to SystemColors.Window Color

textBox.BackColor = System.Drawing.SystemColors.Window;

When this property is set to true, the contents of the control cannot be changed by the user at runtime. With this property set to true, you can still set the value of the Text property in code. You can use this feature instead of disabling the control with the Enabled property to allow the contents to be copied and ToolTips to be shown.

Use the ReadOnly property on the TextBox.

myTextBox.ReadOnly = true;

But Remember: TextBoxBase.ReadOnly Property

When this property is set to true, the contents of the control cannot be changed by the user at runtime. With this property set to true, you can still set the value of the Text property in code. You can use this feature instead of disabling the control with the Enabled property to allow the contents to be copied and ToolTips to be shown.

If you want your TextBox uneditable you should make it ReadOnly.

You can try using:

textBox.ReadOnly = true;
textBox.BackColor = System.Drawing.SystemColors.Window;

The last line is only neccessary if you want a non-grey background color.

If you want to do it using XAML set the property isReadOnly to true.

Just set in XAML:

        <TextBox IsReadOnly="True" Style="{x:Null}" />

So that text will not be grayed-out.

This is for GridView.

 grid.Rows[0].Cells[1].ReadOnly = true;

Enabled="false" in aspx page