473,779 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4043
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.NativeWin dow 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.NativeWin dow 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
6001
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 submit the form only when user will hit submit button. Thanks for any help.
2
2154
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
13274
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. I went ahead and wrote my own bit of code so I'm sharing it here for everyone. Even though it doesn't really disable the button by greying it out, it prevents the multiple submissions which it what I was attempting to prevent all along. ...
14
2348
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) {alert("Temperature entered is out of range."); return;} } I enter data into the first textbox and move the cursor to the second textbox. The function is properly called. Since textbox2 is empty, when I
11
2174
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 in the clipboard... If only I could detect some kind of outgoing message that the clipboard is about to paste, then I could check to see if my app is currently in focus and allow/deny as necessary.
17
5484
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 problem where a user (and me it has to be said) just either highlights the email address with their mouse (or Ctrl-A) and then Ctrl-C, Ctrl-P (or right-click copy, right-click paste) into the next field down.
5
1513
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 entered in the TextBox. If the TextBox doesn't get validated, I want to display messages to the user which should be as precise as possible for the user to easily identify where he erred. This is how I did it: ...
2
2290
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 internet since I guessed someone would have faced this problem before but of no avail. Do we have pointers on how I should go about doing this??
2
2133
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 of invalid data on the text box while it should allow numeric strting to be pasted.
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.