Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to disable "Ctrl+A, Ctrl+C" buttons on WebBrowser?

How to disable "Ctrl+A, Ctrl+C" buttons on WebBrowser?

Scheduled Pinned Locked Moved C#
helptutorialquestion
7 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    COBECTb
    wrote on last edited by
    #1

    Hi all! Sorry for my poor english.... Here my problem, I created WebBrowser,and now I need to disable, "Select_all" and "Copy" fulctions in browser. I disabled ContextMenu, but keys Ctrl+A, Ctrl+C working. I tryed to using ProcessCmdKey,ProcessDialogKey,for catching this Keys but "Ctrl+A, Ctrl+C" are not catching.... If somebody knows how do it, please help me... P.S. Sorry for my mistakes.

    V 1 Reply Last reply
    0
    • C COBECTb

      Hi all! Sorry for my poor english.... Here my problem, I created WebBrowser,and now I need to disable, "Select_all" and "Copy" fulctions in browser. I disabled ContextMenu, but keys Ctrl+A, Ctrl+C working. I tryed to using ProcessCmdKey,ProcessDialogKey,for catching this Keys but "Ctrl+A, Ctrl+C" are not catching.... If somebody knows how do it, please help me... P.S. Sorry for my mistakes.

      V Offline
      V Offline
      Vipin Venugopal
      wrote on last edited by
      #2

      Try this. var isIE = ( document.all != null ); function initIframe() { if ( isIE ) { //wiring to onkeydown event editor.attachEvent('onkeydown', editorEvents); ... } else { editor.addEventListener('keypress', editorEvents, true); ... } } function editorEvents(evt) { //this is just old habit evt = ( evt == null ) ? event; evt; var keyCode = evt.keyCode ? evt.keyCode : evt.charCode; var keyCodeChar = String.fromCharCode(keyCode).toLowerCase(); if ( !isIE )//-->If FireFox { if (evt.type=='keypress' && evt.ctrlKey) { ... } } if ( isIE )//-->If IE { //changed the type to "keydown" to catch new wiring. if (evt.type=='keydown' && keyCodeChar=='v' && evt.ctrlKey) { //do something. //setting the returnValue will cause the event to stop bubbling. evt.returnValue = false; //no return needed } } return true; } Vipin

      C 1 Reply Last reply
      0
      • V Vipin Venugopal

        Try this. var isIE = ( document.all != null ); function initIframe() { if ( isIE ) { //wiring to onkeydown event editor.attachEvent('onkeydown', editorEvents); ... } else { editor.addEventListener('keypress', editorEvents, true); ... } } function editorEvents(evt) { //this is just old habit evt = ( evt == null ) ? event; evt; var keyCode = evt.keyCode ? evt.keyCode : evt.charCode; var keyCodeChar = String.fromCharCode(keyCode).toLowerCase(); if ( !isIE )//-->If FireFox { if (evt.type=='keypress' && evt.ctrlKey) { ... } } if ( isIE )//-->If IE { //changed the type to "keydown" to catch new wiring. if (evt.type=='keydown' && keyCodeChar=='v' && evt.ctrlKey) { //do something. //setting the returnValue will cause the event to stop bubbling. evt.returnValue = false; //no return needed } } return true; } Vipin

        C Offline
        C Offline
        COBECTb
        wrote on last edited by
        #3

        Thank's for You help, but how can I use Your sample for axWebBrowser1? I'm only junior in programming, and very much I don't understand... :(

        V 1 Reply Last reply
        0
        • C COBECTb

          Thank's for You help, but how can I use Your sample for axWebBrowser1? I'm only junior in programming, and very much I don't understand... :(

          V Offline
          V Offline
          Vipin Venugopal
          wrote on last edited by
          #4

          paste this code in the key press event of the textbox or text area where u want to disable the Ctrl+V or Ctrl+C keypress. Vipin

          C 1 Reply Last reply
          0
          • V Vipin Venugopal

            paste this code in the key press event of the textbox or text area where u want to disable the Ctrl+V or Ctrl+C keypress. Vipin

            C Offline
            C Offline
            COBECTb
            wrote on last edited by
            #5

            Sorry but my WebBrowser was created in Windows Application, VS 2003, FW 1.1, here sample: private AxSHDocVw.AxWebBrowser axWebBrowser1; private void Form1_Load(object sender, System.EventArgs e) { object oURL = "www.codeproject.com"; object oEmpty = ""; axWebBrowser1.Navigate2(ref oURL, ref oEmpty, ref oEmpty, ref oEmpty, ref oEmpty); } //Event which open links in new windows\ private void axWebBrowser1_NewWindow2(object sender, AxSHDocVw.DWebBrowserEvents2_NewWindow2Event e) { if (this.axWebBrowser1.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { e.ppDisp = null; e.cancel = true; return; } FEX f1 = new FEX(); f1.Text = "(New window)"; e.ppDisp = f1.axWebBrowser1.Application; f1.Show(); } And how I can use Your sample? Sorry but I don't know....:(

            V 1 Reply Last reply
            0
            • C COBECTb

              Sorry but my WebBrowser was created in Windows Application, VS 2003, FW 1.1, here sample: private AxSHDocVw.AxWebBrowser axWebBrowser1; private void Form1_Load(object sender, System.EventArgs e) { object oURL = "www.codeproject.com"; object oEmpty = ""; axWebBrowser1.Navigate2(ref oURL, ref oEmpty, ref oEmpty, ref oEmpty, ref oEmpty); } //Event which open links in new windows\ private void axWebBrowser1_NewWindow2(object sender, AxSHDocVw.DWebBrowserEvents2_NewWindow2Event e) { if (this.axWebBrowser1.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { e.ppDisp = null; e.cancel = true; return; } FEX f1 = new FEX(); f1.Text = "(New window)"; e.ppDisp = f1.axWebBrowser1.Application; f1.Show(); } And how I can use Your sample? Sorry but I don't know....:(

              V Offline
              V Offline
              Vipin Venugopal
              wrote on last edited by
              #6

              if ( e.Control && e.KeyCode == Keys.A || e.Control && e.KeyCode == Keys.C ) { MessageBox.Show( "Control key + A pressed"); } let me know if this works. Vipin

              C 1 Reply Last reply
              0
              • V Vipin Venugopal

                if ( e.Control && e.KeyCode == Keys.A || e.Control && e.KeyCode == Keys.C ) { MessageBox.Show( "Control key + A pressed"); } let me know if this works. Vipin

                C Offline
                C Offline
                COBECTb
                wrote on last edited by
                #7

                Hi! Sorry but WebBrowser haven't event KeyDown.... And Your sample doesn't work... In my sample, some keys work normal...but "Ctrl+A, Ctrl+C" - does'nt work. protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == (Keys.Control | Keys.N))//Normal { if (this.axWebBrowser1.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { return false; } FEX f1 = new FEX (); f1.Text = "(New window)"; f1.Show(); return true; } else if (keyData == (Keys.Control | Keys.Q))//normal { MessageBox.Show("Q"); return true; } else if (keyData == (Keys.Escape)) { this.Close(); return true; } else if(keyData == (Keys.A | Keys.Control)) { MessageBox.Show("113"); //Doesn't work return true; } else { return base.ProcessCmdKey(ref msg, keyData); } } P.S. Sorry for my mistakes!!!

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups