Link to home
Start Free TrialLog in
Avatar of SwamyN
SwamyN

asked on

how to strict copy paste on Textbox in vb6??

hi, how to strict copy paste on Textbox in vb6?? bcz sometime i strict user to enter only aplhabets but using copy paste he can insert numeric value.
Avatar of basicinstinct
basicinstinct
Flag of Australia image

How about using the 'change' event to check the contents of the textbox?  That way, if the user manages to insert an illegal character in any way you can strip it out...
Avatar of MilanKM
MilanKM

Simply take a Timer control Set Timer1.Enable= True & Interval=1 Then put the following code

Private Sub Timer1_Timer()
   Clipboard.Clear
End Sub

Hope this helps
MilanKM
use masked text edit control, then you can set exactly what can be inserted in the textbox
ASKER CERTIFIED SOLUTION
Avatar of nayernaguib
nayernaguib
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry! You need to set the Locked property to True, not False!
Setting the Locked property of the textbox to True also prevents pasting text to the textbox.

_______________

  Nayer Naguib
Avatar of SwamyN

ASKER

We can take care on Validate Event But instead of this if any other Property or Method Disable copy Paste on Particular Textbox.
As I mentioned before, setting the Locked property to True will prevent pasting text to the textbox. In this case, you will need to programmatically modify textbox contents and cursor location (see my first post). Note that setting the Locked property to True will not disable the textbox (as in the case of setting the Enabled property to False); it only prevents editing the text directly by the user, but you can still handle keyboard and mouse events and modify textbox contents programmatically.

_______________

  Nayer Naguib
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
MilanKM: You code will *indeed* disable the textbox context menu, but will definitely *not* disable Ctrl+V. :-)

_______________

  Nayer Naguib
Again I missed one thing, thanks nayer to knock me.

Ok, to disable "Ctrl+V" ___  put the following code in the KeyPress event, The Ascii value of Ctrl+V is 22.

Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 22 Then
       MsgBox "Not Alpha", vbCritical
       KeyAscii = 0
    End If
End Sub

Thanks
MilanKM
Ok, Swami, now I think it will work for u for a single/ perticular TextBox. So, waiting for ur reply.

Thanks
MilanKM
Avatar of SwamyN

ASKER

ok MilanKm
but when we rightclick on textbox then that condition Paste is allow.
how can i manage it.
thanks
swamy
>> but when we rightclick on textbox then that condition Paste is allow

Is not code not working..? See the following section

Private Sub Form_Load()
    Call Hook(Text1.hWnd) ' Assuming Text1 is the textbox, change it
End Sub

Here put the correct textbox name. I think u can understand what I mean.
If there any other problem then pls explain

Thanks
MilanKM
If U need to disable more than one textbox then do as follows

Call Hook(Text1.hWnd)
Call Hook(Text2.hWnd)
Call Hook(Text2.hWnd)

Also don't forget to put the keypress Event code to disable "ctrl+v"

Thanks
MilanKM
Hi Venabili,

I think, after my last two comments, it's a solution. But didn't get any reply from the asker after waiting for long.

Thanks
MilanKM