469,608 Members | 2,462 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,608 developers. It's quick & easy.

How to prevent Pasting into textbox?

Hi,

I'm developing an application with VB.NET 2003 and I want to forbid
pasting into a textbox.

The problem is not the context menu, but the Ctrl+V shortcut.
How can I prevent that the user can paste anything into a textbox, even
if (maybe) another shortcut for Pasting has been defined?

Thanks in advance!

Beste Regards,

HKSHK
Oct 7 '06 #1
6 3781
Ctrl+V can be can trapped using the keydown event. Not sure what you
could do about the "other shortcuts" though.

Thanks,

Seth Rowe

HKSHK wrote:
Hi,

I'm developing an application with VB.NET 2003 and I want to forbid
pasting into a textbox.

The problem is not the context menu, but the Ctrl+V shortcut.
How can I prevent that the user can paste anything into a textbox, even
if (maybe) another shortcut for Pasting has been defined?

Thanks in advance!

Beste Regards,

HKSHK
Oct 7 '06 #2

HKSHK wrote:
Hi,

I'm developing an application with VB.NET 2003 and I want to forbid
pasting into a textbox.

The problem is not the context menu, but the Ctrl+V shortcut.
How can I prevent that the user can paste anything into a textbox, even
if (maybe) another shortcut for Pasting has been defined?

Thanks in advance!

Beste Regards,

HKSHK
Well, you can override the textbox's wndproc method to capture WM_PASTE
messages. Basically, you would do something like:

Private Const WM_PASTE As Integer = &H302

Protected Override Sub WndProc (ByRef m As Message)
If m.Msg = WM_PASTE
m.Result = IntPtr.Zero
Else
MyBase.WndProc (m)
End If
End Sub

You might have to play with that a little, but that should be fairly
close....

--
Tom Shelton

Oct 7 '06 #3
Dear Mr. Shelton,
Well, you can override the textbox's wndproc method to capture WM_PASTE
messages. Basically, you would do something like:

Private Const WM_PASTE As Integer = &H302

Protected Override Sub WndProc (ByRef m As Message)
If m.Msg = WM_PASTE
m.Result = IntPtr.Zero
Else
MyBase.WndProc (m)
End If
End Sub
Thank you for the code. But do you know any way without having to create
a custom control? I would like to use it as a function which I can use
on any textbox.

Thanks again for your help!

Best Regards,

HKSHK
Oct 8 '06 #4

HKSHK wrote:
Dear Mr. Shelton,
Well, you can override the textbox's wndproc method to capture WM_PASTE
messages. Basically, you would do something like:

Private Const WM_PASTE As Integer = &H302

Protected Override Sub WndProc (ByRef m As Message)
If m.Msg = WM_PASTE
m.Result = IntPtr.Zero
Else
MyBase.WndProc (m)
End If
End Sub

Thank you for the code. But do you know any way without having to create
a custom control? I would like to use it as a function which I can use
on any textbox.

Thanks again for your help!

Best Regards,

HKSHK
Probably not with a function - but I am contemplating a couple of other
alternatives... Like using a class that implements IMessageFilter. Or
maybe something using NativeWindow. Let me play a little and get back
to you :)

--
Tom Shelton

Oct 8 '06 #5

Tom Shelton wrote:
HKSHK wrote:
Dear Mr. Shelton,
Well, you can override the textbox's wndproc method to capture WM_PASTE
messages. Basically, you would do something like:
>
Private Const WM_PASTE As Integer = &H302
>
Protected Override Sub WndProc (ByRef m As Message)
If m.Msg = WM_PASTE
m.Result = IntPtr.Zero
Else
MyBase.WndProc (m)
End If
End Sub
Thank you for the code. But do you know any way without having to create
a custom control? I would like to use it as a function which I can use
on any textbox.

Thanks again for your help!

Best Regards,

HKSHK

Probably not with a function - but I am contemplating a couple of other
alternatives... Like using a class that implements IMessageFilter. Or
maybe something using NativeWindow. Let me play a little and get back
to you :)
Ok, System.Windows.Forms.NativeWindow is the way to go. They even show
an example of subclassing a form using the NativeWindow class. I will
try and throw together a simple example for you if that isn't
sufficeint.

--
Tom Shelton

Oct 9 '06 #6
Dear Mr. Shelton,
Ok, System.Windows.Forms.NativeWindow is the way to go. They even show
an example of subclassing a form using the NativeWindow class. I will
try and throw together a simple example for you if that isn't
sufficeint.
Thanks for the tip and the offer. I'll see what I can do by myself since
the example seems to be quite clear (Keep my fingers crossed... ;-) ).

Thanks again!

Best Regards,

HKSHK
Oct 9 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Pamela Chatterjee | last post: by
2 posts views Thread by ccll20022000 | last post: by
14 posts views Thread by Ed Jay | last post: by
11 posts views Thread by RobKinney1 | last post: by
5 posts views Thread by rn5a | last post: by
2 posts views Thread by AjitGoel | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.