Как сделать textbox неактивным c
Перейти к содержимому

Как сделать textbox неактивным c

  • автор:

How to disable textbox from editing?

I want to use a text box to display some text. I can not disable it, because then the scroll bar will not work.

How can I prevent editing within the multi-line textbox, yet make it appear as if it is enabled, so that the scroll bar works correctly?

kc2001's user avatar

HelpNeeder's user avatar

4 Answers 4

You can set the ReadOnly property to true.

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.

Как сделать textbox неактивным c

This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.

Visual studio home link

  • ProfileText
  • Sign in

Answered by:

Question

I’ve noticed that the .Locked property of the TextBox in C# can only be changed at design time. I need to change it at run time. Is there any way?

Actually, my goal is to lock the textbox in the runtime so that the user cannot modify it but still can copy it to clipboard. Is there any way to do this? I remember that the .Locked property was able to be changed in VB6. I don’t know why it is made a ReadOnly property in C#. Any info about this?

Как сделать textbox неактивным c

I want to use a text box to display some text. I can not disable it, because then the scroll bar will not work.

How can I prevent editing within the multi-line textbox, yet make it appear as if it is enabled, so that the scroll bar works correctly?

user avatar

user avatar

4 Answers 4

You can set the ReadOnly property to true.

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.

The TextBox has a property called ReadOnly . If you set that property to true then the TextBox will still be able to scroll but the user wont be able to change the value.

As mentioned above, you can change the property of the textbox «Read Only» to «True» from the properties window.

enter image description here

«true» property will make the text box readonly activate. and «false» will make it in regular form. Thanks.

Сделать TextBox недоступным для редактирования

Как-то я хочу, чтобы он был отключен, но с несерым передним цветом.

8 ответов

Для не-серого фона вы можете изменить TextBox.BackColor свойство в SystemColors.Window Color

Если для этого свойства установлено значение true, содержимое элемента управления не может быть изменено пользователем во время выполнения. Если для этого свойства установлено значение true, вы все равно можете установить значение свойства Text в коде. Вы можете использовать эту функцию вместо отключения элемента управления с помощью свойства Enabled, чтобы разрешить копирование содержимого и отображение всплывающих подсказок.

Используйте свойство ReadOnly в TextBox.

Если для этого свойства установлено значение true, содержимое элемента управления не может быть изменен пользователем во время выполнения . Если для этого свойства установлено значение true, вы можете по-прежнему устанавливать значение свойства Text в коде . Вы можете использовать эту функцию вместо отключения элемента управления с помощью Включено свойство, позволяющее копировать содержимое и отображать всплывающие подсказки. показано.

Вы можете попробовать использовать:

Последняя строка необходима только в том случае, если вам нужен не серый цвет фона.

Просто установите в XAML:

Так что текст не будет выделен серым цветом.

Если вы хотите, чтобы ваш TextBox не редактировался, сделайте его Только чтение.

Если вы хотите сделать это с помощью XAML, установите для свойства isReadOnly значение true .

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *