vb.net - How to capture mouse right click paste function in Winforms -


i know how capture right click , paste option through mouse click. winforms application. modifying contents of clipboard before pasting. able perform through ctrl+v not able find way handle mouse right click.

i have tried far:

   private const wm_paste integer = &h302    protected overrides sub wndproc(byref msg message)         if msg.msg = wm_paste andalso clipboard.containstext()             clipboard.settext(clipboard.gettext().replace(vbcrlf, " "))         end if         mybase.wndproc(msg)     end sub 

you have process wm_paste windows message using wndproc (a list of messages can found here).

for example, textbox print text pasted (no matter how) console instead of displaying itself:

class capturepastebox     inherits textbox      protected overrides sub wndproc(byref m message)         if m.msg = &h302 andalso clipboard.containstext()             dim text = clipboard.gettext()             '' text             console.writeline(text)             return '' return text won't pasted textbox         end if         mybase.wndproc(m)     end sub end class 

in response comment:

the combobox-control needs special treatment, since

when sent combo box, wm_paste message handled edit control.

so can use following function/class using nativewindow:

<system.runtime.interopservices.dllimport("user32.dll", setlasterror := true)> _ private shared function findwindowex(hwndparent intptr, hwndchildafter intptr, lpszclass string, lpszwindow string) intptr end function  public class pastehandler inherits nativewindow     protected overrides sub wndproc(byref m message)     if m.msg = &h302         clipboard.settext(clipboard.gettext().replace("e", "xxx"))     end if      mybase.wndproc(m)     end sub end class 

and use combobox:

'' edit control of combobox dim lhwnd intptr = findwindowex(yourcombobox.handle, intptr.zero, "edit", nothing)  '' assign edit control pastehandler dim p new pastehandler() p.assignhandle(lhwnd) 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -