473,396 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3999
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pamela Chatterjee | last post by:
In my Web Form I have more than one Textbox for user input. If I hit enter to any Textbox its submitting the form. How can I prevent Form submission if users hit enter to the textbox? I want to...
2
by: ccll20022000 | last post by:
Just curious. I am writing a description for a site I want developers to build (mostly in flash) I was wondering if it is possible to prevent pasting into a field Thanks! ccll20022000
2
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. ...
14
by: Ed Jay | last post by:
On a multi-textbox form, linked to an external js, I use onBlur to call: function chkNum(cellname) { var str = document.getElementById(cellname).value.toString(10); if (str < 28 || str > 36)...
11
by: RobKinney1 | last post by:
Hello, I am looking for a clever way to prevent someone from pasting copied text outside of my app. I know how to monitor the clipboard and get an WM_DRAWCLIPBOARD message when text is stored...
17
by: emma.sax | last post by:
Hi all, I have a form where we would like the user to input their email address twice, to ensure they've typed it correctly, as is found on most sign-ups I'm looking for a solution to the...
5
by: rn5a | last post by:
A Web Form has a TextBox within a DataGrid wherein users are expected to enter only whole numbers. It should be validated so that the TextBox doesn't remain blank or any non-numeric data is...
2
by: AjitGoel | last post by:
Hi; I need to create a custom textbox control which will not allow a user to paste text from the clipboard. The user has to always type the text into the textbox. I tried searching on the...
2
by: Chinmay1985 | last post by:
Hi, Currently we have a text box which takes only Numbers. but using control keys and mouse we are able to paste string which has invalid data (i.e. !!@nmbdnm). So how can I restrict the pasting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.