3
Reply

Display an error with tool tip

Ask a question
Dorababu Meka

Dorababu Meka

14y
2.4k
1
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)