How to disable "Ctrl+A, Ctrl+C" buttons on WebBrowser?
-
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.
-
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.
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
-
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
-
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... :(
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
-
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
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....:(
-
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....:(
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
-
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
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!!!