Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Any way to bypass Validating event when closing form?
Message
De
11/02/2008 14:55:22
John Baird
Coatesville, Pennsylvanie, États-Unis
 
 
À
11/02/2008 13:49:49
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Divers
Thread ID:
01291525
Message ID:
01291586
Vues:
8
>I do not have an event handler in place, but the closing event does not happen if an invalid entry is in the text box. Here is my validating handler code. Am I doing something stupid here?


I set up this test code in a windows forms project and it works just fine. The exit takes place everytime regardless of wether I type "1234" or "abcd" in the box and hit the X.
      private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void textBox1_Validating(object sender, CancelEventArgs e)
        {
            // Cast the sender object as a control
            Control oControl = (Control)sender;

            // try to convert the entry in the textbox
            // to a number

            double nNumber;

            try
            {
                if (oControl.Text.Length == 0)
                    oControl.Text = "0";
                else
                    nNumber = Convert.ToDouble(oControl.Text);
            }
            catch
            {
                e.Cancel = true;
                oControl.Select();
                errorProvider1.SetError(oControl, "You must enter a numeric value");
            }
        }
    }
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform