Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
-->
TitleRestrict paste in a TextBox's context menu
KeywordsTextBox, right click, popup, context menu
CategoriesControls
 
By Ariel Canievsky.

To make sure that the type of data in the Clipboard is or not a numeric value. Test this:

    If Val(Clipboard.GetText) = 0 Then Clipboard.Clear

And then, if you don't wanna loose the data of the Clipboard, first copy it to a variable and then give it back to the clipboard. The full code is liisted here:

 
Dim clp As String

Private Sub t_MouseDown(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    RetainClp
End Sub

Private Sub t_KeyPress(KeyAscii As Integer)
    If KeyAscii = 8 Then Exit Sub
    If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub

Private Sub t_LostFocus()
    If Len(clp) > 0 Then Clipboard.SetText clp
End Sub

Sub RetainClp()
    If Val(Clipboard.GetText) = 0 Then
        clp = Clipboard.GetText
        Clipboard.Clear
    End If
End Sub
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated