Silverlight / WPF - Disable browser print button

Asked By gopal krish on 05-Jun-12 11:27 AM

Hello,

We have an SL5 application and the client wants the browser print button to be disabled, or in some other way ensure that the user cannot print the page.

Does anyone know if this is possible?

need ur suggestions..

regards
gopal.s

Peter Bromberg replied to gopal krish on 05-Jun-12 12:56 PM
You can do it with CSS - but---
 
<style type="text/css" media="print">
BODY {display:none;visibility:hidden;}
</style> 

Anybody can still deafeat it using Print Screen
Neha Garg replied to gopal krish on 05-Jun-12 01:33 PM
Hi Gopal,

try the below mentioned codes:

<div id="silverlightObjDiv">
 
</div>

Javascript


<script>
document.getElementById('silverlightObjDiv').oncontextmenu = disableRightClick;
function disableRightClick(e) {
  if (!e) e = window.event;
  if (e.preventDefault) {
    e.preventDefault();
  } else {
    e.returnValue = false;
  }
}
</script>
kalpana aparnathi replied to gopal krish on 05-Jun-12 01:51 PM
hi,

Open Registry editor and macke the following changes:


HKCU\\Software\\Policies\\Microsoft\\Internet Explorer\\Restrictions\\NoPrinting"
"REG_DWORD" value:1

Regards,
dipa ahuja replied to gopal krish on 05-Jun-12 02:28 PM
<head runat="server">
 
  <title></title>
  <script type="text/javascript">    
  function disableCtrlKeyCombination(e) {
    //list all CTRL + key combinations you want to disable
    var forbiddenkeys = new Array('a', 'n', 'c', 'x', 'v', 'j', 'p');
    var key;
    var isCtrl;
    if (window.event) {
    key = window.event.keyCode;   //IE
    if (window.event.ctrlKey)
      isCtrl = true;
    else
      isCtrl = false;
    }
    else {
    key = e.which;   //firefox
    if (e.ctrlKey)
      isCtrl = true;
    else
      isCtrl = false;
    }
 
    //if ctrl is pressed check if other key is in forbidenKeys array
    if (isCtrl) {
    for (i = 0; i < forbiddenkeys.length; i++) {
      //case-insensitive comparation
      if (forbiddenkeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase()) {
      alert("Key combination CTRL + "
          + String.fromCharCode(key)
          + " has been disabled.");
      return false;
      }
    }
    }
    return true;
  }
  var oEventUtil = new Object();
  oEventUtil.AddEventHandler = function (oTarget, sEventType, fnHandler) {
    if (oTarget.addEventListener) {
    oTarget.addEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
    oTarget.attachEvent('on' + sEventType, fnHandler);
    } else {
    oTarget['on' + sEventType] = fnHandler;
    }
  }
  
 
</script>
</head>
<body onkeypress="return disableCtrlKeyCombination(event);"
  onkeydown="return disableCtrlKeyCombination(event);">  
 
 
Jitendra Faye replied to gopal krish on 06-Jun-12 12:42 AM
By my knowledge you can not disable print button of browser because it is browser functionality, We can access browser information but you can not set setting for browser,