我已经创建了一个静态类数字文本框但我不想控制用户在te文本框中粘贴的内容.对于处理粘贴事件我使用textchanged事件:
static public void textChanged(EventArgs e, TextBox textbox, double tailleMini, double tailleMaxi, string carNonAutorisé)
{
//Recherche dans la TextBox, la première occurrence de l'expression régulière.
Match match = Regex.Match(textbox.Text, carNonAutorisé);
/*Si il y a une Mauvaise occurence:
* - On efface le contenu collé
* - On prévient l'utilisateur
*/
if (match.Success)
{
textbox.Text = "";
MessageBox.Show("Votre copie un ou des caractère(s) non autorisé", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
tailleTextBox(textbox, tailleMini, tailleMaxi);
}
Run Code Online (Sandbox Code Playgroud)
在另一个类中,我使用这样的静态方法
private void tbxSigné_TextChanged(object sender, EventArgs e)
{ …Run Code Online (Sandbox Code Playgroud)