c#实现word,winWordControl 文档不允许复制、粘贴、隐藏工具栏、快捷保存

1.隐藏工具栏

//隐藏工具栏
for (int i = 1; i <= winWordControl1.document.CommandBars.Count; i++) { winWordControl1.document.CommandBars[i].Enabled = false;//置灰
winWordControl1.document.CommandBars[i].Visible = false;//不可见
}

本语句完成的功能是对整体工具条的隐藏,如:常用,格式等工具条,而工具条内具体的功能点隐藏如下:

 for(int i=1;i<=winWordControl1.document.ActiveWindow.Application.CommandBars["Standard"].Controls.Count;i++)
{
if ("打印(&P)打印预览(&V)".IndexOf(winWordControl1.document.ActiveWindow.Application.CommandBars["Standard"].Controls[i].Caption)!=-1) { winWordControl1.document.ActiveWindow.Application.CommandBars["Standard"].Controls[i].Enabled = true; } else { winWordControl1.document.ActiveWindow.Application.CommandBars["Standard"].Controls[i].Enabled = false; winWordControl1.document.ActiveWindow.Application.CommandBars["Standard"].Controls[i].Visible = false; } }

本代码实现“常用”工具条,打印和打印预览显示、可操作。

2.不允许复制、粘贴

  object missing = Type.Missing;
  if (winWordControl1.document.Application.ActiveDocument.ProtectionType == Word.WdProtectionType.wdNoProtection)
  {
      winWordControl1.document.Application.ActiveDocument.Protect(Word.WdProtectionType.wdAllowOnlyFormFields, ref missing, ref missing);
  }

3.屏蔽快捷键方式

//不允许快捷键保存
int keyControl = winWordControl1.document.Application.BuildKeyCode(Word.WdKey.wdKeyControl, ref  missing, ref  missing, ref missing);
int cKey = winWordControl1.document.Application.BuildKeyCode(Word.WdKey.wdKeyS, ref  missing, ref  missing, ref missing);
winWordControl1.document.Application.get_FindKey(keyControl | cKey, ref missing).Disable();

屏蔽其他的快捷键参考上面代码就可。

原文地址:https://www.cnblogs.com/lecone/p/csharp-word-winWordControl.html