Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I overrides ProcessCdmKey to make copy, paste, ... like this:
VB
Protected Overloads Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
        If keyData = DirectCast(Shortcut.CtrlV, Keys) Then
            Me.ClearSelection()
            Dim text As String = Clipboard.GetText()
            ' SendKeys.Send(text);
            For k As Integer = 0 To text.Length - 1
                ' Can not use SendKeys.Send
                SendCharKey(text(k))
            Next
            Return True
        ElseIf keyData = DirectCast(Shortcut.CtrlC, Keys) Then
            Clipboard.SetText(Me.SelectedText)
            Return True
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function


VB
Private Sub SendCharKey(ByVal pChar As Char)
        Dim msg As New Message()
        msg.HWnd = Me.Handle
        msg.Msg = WM_CHAR
        ' It has something wrong cannot convert to IntPtr
        ' Can i convert or make other away
        msg.WParam = pChar 'DirectCast(pChar, IntPtr)
        msg.LParam = IntPtr.Zero
        MyBase.WndProc(msg)
    End Sub


In Sub SendKeyChar have error in convert. I note in that sub.
Thanks a lot
Posted

1 solution

From my limited knowledge of VB.NET I believe you want to use CType rather than DirectCast when changing your char to an IntPtr

Private Sub SendCharKey(ByVal pChar As Char)
        Dim msg As New Message()
        msg.HWnd = Me.Handle
        msg.Msg = WM_CHAR
        '
        msg.WParam = CType(pChar, IntPtr)
        msg.LParam = IntPtr.Zero
        MyBase.WndProc(msg)
End Sub


http://www.codeproject.com/KB/vb/DirectcastVsCtype.aspx[^]
 
Share this answer
 
Comments
thuyphuongid 5-Jun-10 2:32am    
Thank you very much.

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