Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
Uday P.Singh 22-Jul-11 5:29am    
not clear!! give more details
tanisha pandey 22-Jul-11 6:43am    
just like we are giving a condition of alphanumeric and digit used in text box in textbox keypress event just like can i define a method to allow user to use Ctrl-C,Ctrl-V and Ctrl-A.
Sergey Alexandrovich Kryukov 23-Jul-11 0:46am    
Tag it! WPF, Forms, ASP.NET, what?
--SA

This is working in my system.

C#
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
 
Share this answer
 
v2
Comments
Dalek Dave 22-Jul-11 7:19am    
Edited for Code Block.
check this out:

input-handling-in-winform[^]

hope it helps :)
 
Share this answer
 
Comments
lukeer 22-Jul-11 7:29am    
Link contains a hint to MaskedTextBox. My 5 for that.
Uday P.Singh 22-Jul-11 7:32am    
thanks :)
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...
 
Share this answer
 
The TextBox control supports Ctrl+C and Ctrl+V without further ado. For Ctlr+A to work, you will have to check in KeyDown event handler for Ctrl key to be pressed.
MyTextBox_KeyDown( object sender, KeyEventArgs e)
{
    if( e.KeyData == ( Keys.A | Keys.Control ))
    {
        SelectAllTextInMyTextBox();
    }
}


How did you implement your check? Depending on the way you did that, it's possible that it doesn't interfere with the hotkeys at all.
 
Share this answer
 
Ctrl+C is not a "special character". Frankly, I don't know what's "special" character. Character is a character, Ctrl+C is not. No characters at all. This is a key combination. There are several levels of interpretation of physical key presses. Characters are produced on the very last stage. Some of them never produce any characters, like those you are asking about. Usually you process key combinations like that are captured by handling events like KeyDown and KeyUp.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900