Read-only text box in C #

In C # , I create a form window for a LAN messenger with two text fields. I need to create a specific text field as read-only, but any text presented to it looks gray, which is undesirable. Is there any way to prevent this?

+6
c # textbox
source share
5 answers

I would use a text box and set ReadOnly to true, ForeColor to Color.Black and BackColor to Color.White. Thus, you can still select the text and copy it using Ctrl-C.

+22
source share

You can replace it with a label or text field in the KeyPress event, set it to true:

void textBox1_KeyPress(object sender, KeyPressEventArgs e) { e.Handled = true; } 
+6
source share

You can set the text color by setting the ForeColor Text Box property.

For example:

myTextBox.ForeColor = Color.Black

+2
source share

To keep the text field white (or a window) when it is read-only, you must explicitly set the BackColor property to Window. To do this, you must first set BackColor to a different value, and then return to the window. The backcolor property must be bold, which means that it is no longer the default value.

+1
source share

Gray indicates the status of the ReadOnly text field. This is a visual indication for a user who does not need to enter text to find that the text field is actually disabled.

If you only need readonly behavior, you'd better use a shortcut instead.

0
source share

All Articles