BigOldDog
asked on
Locking a textbox
I am changeing to VB 2010 Express from VB5 and I have run into a problem with locking a text box from my program.
Imagime a form with a button and a text box on it. When the button is clicked the text box should be locked to prevent data entry.
In the buttons Click event I tried to enter
Me.TextBox1.Locked = True
But apparently this property is not available at runtime, it's there in TextBox1's property sheet at Design time.
Iguess I must be doing something wrong.
Imagime a form with a button and a text box on it. When the button is clicked the text box should be locked to prevent data entry.
In the buttons Click event I tried to enter
Me.TextBox1.Locked = True
But apparently this property is not available at runtime, it's there in TextBox1's property sheet at Design time.
Iguess I must be doing something wrong.
Another alternative is to set the ReadOnly property to true.
Both Enabled=False and ReadOnly=True will prevent data entry. If you use the ReadOnly, you can still high light the content and do a CTRL-C (copy).
ASKER
Enabled = False is no good as it "grays" out the text.
I guess I could set ForeColor to correct this, though I do not know if this will work on a disabled control.
I have not tried ReadOnly = True so I cannot say if that would be OK.
The question remains, why is "Locked" not available? All the help documentation seems to say it should be
I guess I could set ForeColor to correct this, though I do not know if this will work on a disabled control.
I have not tried ReadOnly = True so I cannot say if that would be OK.
The question remains, why is "Locked" not available? All the help documentation seems to say it should be
In button clicked event write
this.txt.KeyPress += new KeyPressEventHandler(textB ox1_KeyPre ss);
private void txt_KeyPress(object sender, KeyPressEventArgs e)
{
txt.readonly=true;
e.Handled = true;
}
Regrds
ramki
this.txt.KeyPress += new KeyPressEventHandler(textB
private void txt_KeyPress(object sender, KeyPressEventArgs e)
{
txt.readonly=true;
e.Handled = true;
}
Regrds
ramki
is a web or windows application? I think Locked is a web property.
Ignore the previous post..
In button clicked event write
this.txt.KeyPress += new KeyPressEventHandler(txt_K eyPress);
Then
private void txt_KeyPress(object sender, KeyPressEventArgs e)
{
txt.readonly=true;
e.Handled = true;
}
Regrds
ramki
In button clicked event write
this.txt.KeyPress += new KeyPressEventHandler(txt_K
Then
private void txt_KeyPress(object sender, KeyPressEventArgs e)
{
txt.readonly=true;
e.Handled = true;
}
Regrds
ramki
Otherwise the easier option is...
Set the ReadOnly property to true and set the Background color to the color you want. When you set the ReadOnly property it changes the background color to Control. This can be changed to whatever you want.
Regards ramki
Set the ReadOnly property to true and set the Background color to the color you want. When you set the ReadOnly property it changes the background color to Control. This can be changed to whatever you want.
Regards ramki
>The question remains, why is "Locked" not available? All the help documentation seems to say it should be
There is no locked property on Winforms Textbox. What documentation are you referring to?
There is no locked property on Winforms Textbox. What documentation are you referring to?
Actually the fact is....
In VB.NET, the locked property doesn't mean the same as it did in VB6. Now it means that the control cannot be moved as design time.
I am referring the latest MSDN....
In VB.NET, the locked property doesn't mean the same as it did in VB6. Now it means that the control cannot be moved as design time.
I am referring the latest MSDN....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK.
TextBox1.ReadOnly = True
Textbox1.BackColor = Color.Yellow
(this happened to be the BackColor of the text box) works, and comes very close to replicating the old VB6 "Locked" property.
When I checked the help documents that I looked at on line I see my error, is there any way to set help to only show Net framework4 information?
TextBox1.ReadOnly = True
Textbox1.BackColor = Color.Yellow
(this happened to be the BackColor of the text box) works, and comes very close to replicating the old VB6 "Locked" property.
When I checked the help documents that I looked at on line I see my error, is there any way to set help to only show Net framework4 information?
Use this It will work..
Regards ramki..