用于检查特殊字符(如Ctrl c)的c#代码 [英] c# code for checking special character like Ctrl c

查看:75
本文介绍了用于检查特殊字符(如Ctrl c)的c#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#中定义了一种方法来检查文本框中的字母数字和数字,但是我想在文本框中使用Ctrl A,Ctrl C和Ctrl V来表示我们在我的方法中编写的代码.

i define a method in c# for checking the alphanumeric and digits in textbox but i want to use Ctrl A, Ctrl C and Ctrl V in textbox for that what code we write in my method.

推荐答案

这在我的系统中有效.

This is working in my system.

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If (IdentifySelectAllCopyPaste(e.KeyChar) = True) Then
            MsgBox("CTRL + A Or CTRL + C Or CTRL + V Not allowed.")
        End If
    End Sub
Public Function IdentifySelectAllCopyPaste(ByVal KeyChar As Char) As Boolean
        Try
            If Asc(KeyChar) = 1 Or Asc(KeyChar) = 3 Or Asc(KeyChar) = 22 Then
                If (Clipboard.ContainsData(DataFormats.Text) = True) Then
                    Clipboard.Clear()
                End If
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            MsgBox("Error", "Error", ex.Message)
            Return False
        End Try
    End Function


签出:

input-handling-in-winform [
check this out:

input-handling-in-winform[^]

hope it helps :)


Don''t.
简单如

CTRL-C和CTRL-V(一定程度上是CTRL-A)是Windows普通用户期望分别进行复制,粘贴和全选的键组合.如果您破坏了这一点,那么用户很容易感到困惑,并且会变得非常讨厌您的应用程序...
Don''t.
Simple as.

CTRL-C and CTRL-V (and CTRL-A to a certain extent) are keys combinations that the average Windows user expects to do Copy, Paste and Select All respectively. If you subvert this, then the user can easily get confused, and will grow to strongly dislike your application...


这篇关于用于检查特殊字符(如Ctrl c)的c#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆