winforms - C# Set the visibility of a label using the result of String.IsNullOrEmpty -


Hi I'm trying to set the visibility of a label based on a text box string empty. I have the following code:

  MyLabel.Visible = String.IsNullOrEmpty (MyTextBox.Text);  

When the text box is left blank, then why not?

Update

I have tried to put this code in an event with a text tag in the text box and it still does not work.

This was an updated issue, it works on the Text_Changed event, though the problem is that it does not work when the form is triggered on processing.

The code starting with my controller class is what is happening to give better information to everyone:

 using  (var frm = new frmAdd ( PersonType.Carer)) {var res = frm.ShowDialog (); If (res == System.Windows.Forms.DialogResult.OK) {if (frm.ValidateInformation ()) // The above code is called here {// Process Here information ...}}}  < / Pre> 

In addition to this, I also forgot that this form is in the Class Library Project (DLL).

I will add a trim to make the user more consistent in terms of spaces:

  MyLabel.Visible = String.IsNullOrEmpty (MyTextBox.Text.Trim ());  

For the rest it is a matter of triggering the code at the right time. TextChanged should cover all but inital status, as addressed by JaredPar, though I will use form_load, not constructor.

After the clarification, edit:
If your label is on a text box frmAdd then the question is controversial, it has been shown that it will not be shown after self-realization.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -