Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi! This is Atta Ur Rahman. I have Two Question. First one is to disable textbox. in form i have radio Button "Male" and "Female". and a textbox " Husband Name" and Husband NIC". when I check "Male" button. I want to disable both the texboxes of husband name and husband nic.
Another question is this, i want to allow the texboxes only alphabets.

What I have tried:

i tried to allow the numeric in tex boxes but i don't know how to not allow the numerics.
private void txbxralativenic_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar) && e.KeyChar != '-' && !char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
            if (txbxralativenic.Text.Length > 14 && !char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }
Posted
Updated 11-Feb-17 3:24am

If textBox1 is the text box for husband name and radioButton1 is the radio for male option, then
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
	textBox1.Enabled = !radioButton1.Checked;
}
For the next question, check this out: User Input Validation in Windows Forms[^]
 
Share this answer
 
Comments
Atta Ur Rahman Pak 11-Feb-17 11:55am    
Thank You sir. My Problem Solved....
Karthik_Mahalingam 11-Feb-17 13:57pm    
if solved, please close this post by clicking "Accept Answer"
Try:
C#
MyTextBox.Enabled = false;


For numeric only input, I wouldn't use a TextBox - you can do it, but it's a bit of a PITA because you have to prevent Pasting as well as keyboard entry.
Instead, I'd suggest you use a NumericUpDown control - it will only allow numbers, and allows you to set a maximum and minimum value as well.
 
Share this answer
 
Comments
Atta Ur Rahman Pak 11-Feb-17 11:55am    
Thanks Sir.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900