How to make TextBox non-interactive in C #
I have a TextBox on a form that I am using to just display data. I set it to ReadOnly, which stops the user from modifying the data displayed in the TextBox. Although the user can still highlight data in the TextBox, how do I disable this?
NOTE. I know using a label would be much easier, although for some reason the label doesn't allow me to display the data as I would like. I want to display a number starting to the right of the display area, IE: "25" even though the label displays "25". I tried to make the label justify and it doesn't solve the problem. Therefore I am using TextBox.
This is simple code C#
and I just wrote it to disable some of my textboxes and buttons. But you can change it according to your requirements:
TextBox[] tbArray = new TextBox[]
{
custid,custname , field, email, phone, address
};
for (int i = 0; i < tbArray.Length; i++)
{
if (status.SelectedIndex == 1)
{
tbArray[i].Enabled = false;
savecust.Enabled = false;
deletecust.Enabled = false;
}
else
{
tbArray[i].Enabled = true;
savecust.Enabled = true;
deletecust.Enabled = true;
}
}
a source to share