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.

+1


a source to share


4 answers


You can display the aligned text in the label by setting the TextAlign property for example. MiddleRight. Remember also to set the AutoSize property to false, otherwise it will resize the label and the position will change to the left.



+2


a source


TextBox1.Enabled = false;

      



Or you can use a label with RightToLeft property set to True

+3


a source


You can change the event handler (for example, in the Enter action) to move the Active property of the form to another control.

+1


a source


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;
    }
}   

      


0


a source







All Articles