Hi gyes
my problem is this:i have some textboxes and one button that is disabled and i want when all the textboxes are filled than the button to become active or enabled
Without knowing anything about how you've named and collected your textboxes you could do something like this (and yes, there are better ways):
private void EnableButton() {
Boolean enable = true;
if (TextBox1.Text.Length == 0) enable = false;
if (TextBox2.Text.Length == 0) enable = false;
if (TextBox3.Text.Length == 0) enable = false;
// repeat until all the textboxes you want to check are done;
Button1.Enabled = enable;
}
Try this code. It will enable button as soon as all buttons will have some text inside.
public Form1()
{
InitializeComponent();
button1.Enabled = false;
TextBox[] tbs = { textBox1, textBox2, textBox3 }; //put all the textBoxes you want in here
foreach (TextBox tb in tbs)
tb.TextChanged += new EventHandler(tb_TextChanged);
}
private void tb_TextChanged(object sender, EventArgs e)
{
EnablingButton();
}
private void EnablingButton()
{
TextBox[] tbs = { textBox1, textBox2, textBox3 };//put all the textBoxes you want in here
bool bEnableButton = true;
foreach (TextBox tb in tbs)
{
if (tb.Text.Equals(String.Empty))
{
bEnableButton = false;
break;
}
}
if (bEnableButton)
button1.Enabled = true;
else
button1.Enabled = false;
}
thanks gyes this is what i was thinking
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.