|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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 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: Show quoteHide quote > 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 HKSHK wrote:
Show quoteHide quote > Hi, Well, you can override the textbox's wndproc method to capture WM_PASTE> > 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 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 Dear Mr. Shelton,
> Well, you can override the textbox's wndproc method to capture WM_PASTE Thank you for the code. But do you know any way without having to create > 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 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 HKSHK wrote:
Show quoteHide quote > Dear Mr. Shelton, Probably not with a function - but I am contemplating a couple of other> > > 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 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 Tom Shelton wrote:
Show quoteHide quote > HKSHK wrote: Ok, System.Windows.Forms.NativeWindow is the way to go. They even show> > 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 :) 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 Dear Mr. Shelton,
> Ok, System.Windows.Forms.NativeWindow is the way to go. They even show Thanks for the tip and the offer. I'll see what I can do by myself since > 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. the example seems to be quite clear (Keep my fingers crossed... ;-) ). Thanks again! Best Regards, HKSHK
VB 6 developers and .Net
Read legacy vb5 files with variant declare in vb.net Running an Access macro from a VB.NETprogram How to assign value to a dropdown box items? need help on optional arg ADOX add bool field efficient routine to parse a text string Memory problem with vb.net + webServices + DLL Set Focus to textbox on tab control clicking on a DataGridView's DataSource property throws exception in designer |
|||||||||||||||||||||||