|
-
January 13th, 2011, 04:43 AM
#1
IF sectence
I have two textboxes.
txtbox1
txtbox2
I want to make a IF sectence which does this:
When i do NOT write txt in txtbox1, the other textbox, txtbox2, will be set to visibility = false
This require that the IF sectence can notice if there is any text in txtbox1.
How can i do this?
Last edited by Fnyx; January 13th, 2011 at 07:06 AM.
-
January 13th, 2011, 10:42 AM
#2
Re: IF sectence
Just call this method to wherever you want to do the checking. You could also make a string variable and check its length, but for a basic solution this should work.
private void checkIfText()
{
if(textbox1.Text != "")
{
textbox2.visible=true;
textbox2.enabled=true;
}
else
{
textbox2.visible=false;
textbox2.enabled=false;
}
}
Last edited by Jermay; January 13th, 2011 at 10:47 AM.
-
January 13th, 2011, 01:41 PM
#3
Re: IF sectence
There's really no reason to make that so verbose. You are already evaluating a boolean in the if statement, so you can accomplish the same thing with a single line.
Code:
textbox2.Visible = (textbox1.Text != String.Empty);
You don't need to set Enabled since an invisible textbox cannot be interacted with anyway.
I would handle the TextChanged event of textbox1 and place that code there.
-
January 14th, 2011, 12:10 AM
#4
Re: IF sectence
I would use the LostFocus or the Leave event of the first textbox and then do what the above post says. If you are populating the textbox as it loads, you may want to check if the form is visible first and then make this check.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|