Dorababu Meka

Dorababu Meka

  • 226
  • 8.3k
  • 1.7m

Display an error with tool tip

Jun 21 2010 6:27 AM
I have written a code for validating text boxes as follows

public class TestClass
        {

            public void RequiredText(TextBox txt, ToolTip newtoolTip)
            {

                if (txt.Text != string.Empty)
                {
                    //txt.Text = "Required";
                    txt.BackColor = System.Drawing.Color.White;
                    newtoolTip.Hide(txt);

                }
                else
                {
                    txt.BackColor = System.Drawing.Color.Tomato;
                    newtoolTip.Show("Required", txt);
                }
            }
        }

In textbox validating i use this

  private void textBox2_Validating(object sender, CancelEventArgs e)
        {
            TestClass test = new TestClass();
           
            test.RequiredText(textBox2, toolTip1);
        }


Now what i need is when i click on submit i would like to display error message for the text boxes that are left empty . If success i would like to save the record. Any idea please

Answers (3)