小编Sef*_*Sef的帖子

在c#中处理粘贴事件

我已经创建了一个静态类数字文本框但我不想控制用户在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)

.net c# regex static-methods paste

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

paste ×1

regex ×1

static-methods ×1