Reputation:
I've got a TextBox on a form that I am using to just display data. I have set it to ReadOnly which stops the user from changing the data displayed in the TextBox. Although the user can still highlight the 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 wont let me display the data how I would like. I want to display a number starting from the right of the display area, IE: " 25", although the label displays it like "25 ". I have tried making the label right-justified this does not solve the issue. Therefore I am using a TextBox.
Upvotes: 1
Views: 14694
Reputation: 1
This is just a simple C#
code and I just wrote it to disable some of my textboxes and button. But, you can change it as per 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;
}
}
Upvotes: 0
Reputation: 11
You can modify an event handler (say, on the Enter action) to move the Active property of the form to another control.
Upvotes: 1
Reputation: 2688
You can display right aligned text in label by setting TextAlign property to e.g. MiddleRight. Remember also to set AutoSize property to false, otherwise it will resize the label and the position will change to left.
Upvotes: 2
Reputation:
TextBox1.Enabled = false;
Or you can use the label with the property RightToLeft set to True
Upvotes: 3