Utilisation de C# dans 2008 Express. J'ai une zone de texte contenant un chemin. J'ajoute un "\" à la fin de Leave Event. Si l'utilisateur appuie sur la touche 'Échap', je veux que l'ancien contenu soit restauré. Quand je tape tout le texte et que j'appuie sur 'Escape', j'entends un bruit sourd et l'ancien texte n'est pas restauré. Voici ce que j'ai jusqu'à présent ...C# événements winforms restaurer le contenu de la zone de texte lors de l'échappement
public string _path;
public string _oldPath;
this.txtPath.KeyPress += new System.Windows.Forms.KeyPressEventHandler(txtPath_CheckKeys);
this.txtPath.Enter +=new EventHandler(txtPath_Enter);
this.txtPath.LostFocus += new EventHandler(txtPath_LostFocus);
public void txtPath_CheckKeys(object sender, KeyPressEventArgs kpe)
{ if (kpe.KeyChar == (char)27)
{
_path = _oldPath;
}
}
public void txtPath_Enter(object sender, EventArgs e)
{
//AppendSlash(sender, e);
_oldPath = _path;
}
void txtPath_LostFocus(object sender, EventArgs e)
{
//throw new NotImplementedException();
AppendSlash(sender, e);
}
public void AppendSlash(object sender, EventArgs e)
{
//add a slash to the end of the txtPath string on ANY change except a restore
this.txtPath.Text += @"\";
}
Merci à l'avance,
Je suggère d'utiliser 'kpe.KeyCode ==' Keys.Escape' au lieu de 'kpe.KeyChar == (char) 27'. – Powerlord