首页 > 解决方案 > 如何更改 Outlook VSTO 中的鼠标指针

问题描述

我正在尝试使用 Outlook 功能区中的自定义按钮将文件上传到远程服务器。发生以下步骤

  1. 用户单击功能区中的上传文件按钮,将看到文件选择器对话框。
  2. 将看到文件选择弹出窗口,用户选择一个或多个文件
  3. 单击确定按钮后,我只想更改默认光标以等待光标
  4. 文件上传完成后,我尝试恢复默认光标

我的代码如下

 public void UploadFiles(Office.IRibbonControl control)
    {
      OpenFileDialog openFileDialog = new OpenFileDialog();
        if (openFileDialog.ShowDialog() == DialogResult.OK)
        {
           Cursor.Current = Cursors.WaitCursor
          //some code which will call rest API to upload file 
           Cursor.Current = Cursors.default
        }
     }

但上面的代码并没有改变光标。该按钮出现在 Outlook 的撰写窗口中

标签: c#outlookvsto

解决方案


您需要导入 Word.DLL 然后使用以下代码

 public void UploadFiles(Office.IRibbonControl control)
  {
     OpenFileDialog openFileDialog = new OpenFileDialog();
    if (openFileDialog.ShowDialog() == DialogResult.OK)
    {
            Outlook.Inspector currentInspector = Globals.ThisAddIn.Application.ActiveInspector();
            Word.Document document = currentInspector.WordEditor;
            Word.Application wordApp = document.Application;
            wordApp.System.Cursor = Word.WdCursorType.wdCursorWait;
            //perform your task
           //Switch to default Cursor 
           wordApp.System.Cursor = Word.WdCursorType.wdCursorNormal; 

 }
 }

推荐阅读