【问题标题】:Outlook add in , text box , delete\backspace not workingOutlook 添加,文本框,删除\退格不起作用
【发布时间】:2010-11-02 04:09:33
【问题描述】:

我开发了一个 Outlook 插件(自定义任务窗格),用户控件中有网络浏览器。

当我在网络浏览器的文本框中写东西时,除了退格键或删除按钮之外的所有东西都运行良好,我无法使用这些键,我错过了什么吗?

【问题讨论】:

    标签: browser key outlook-addin backspace


    【解决方案1】:

    我迟到了几年,但我设法解决了这个问题。解决此问题的最简单方法是确保正确关注输入字段,因此您需要能够在正在加载的任何页面上运行自己的 javascript。

    我在页面上运行的javascript如下(使用jQuery):

    $(document).on("click", function (e) {
      // first let the add-in give focus to our CustomTaskPane
      window.external.focus();
      // then in our web browser give focus to whatever element was clicked on
      $(e.target).focus();
    });
    

    window.external 变量包含从插件(我假设是 c# 或 VB)运行的代码,这些代码是公开的,因此我们可以从网页交互回加载项。

    在自定义任务窗格的插件代码中设置window.external的上下文:

    // event when webBrowser is finished loading document
    private void webBrowser1_DocumentCompleted(object sender,     WebBrowserDocumentCompletedEventArgs e)
        {
            // sets context of window.external to functions defined on this context
            webBrowser1.ObjectForScripting = this;
        }
    

    还有一种公共的聚焦方法:

    // can be called by the web browser as window.external.focus()
    public void focus()
    {
        this.Focus();
    }
    

    这对我有用,我希望它对其他人有帮助。虽然请注意,如果用户键盘使用选项卡导航,这可能不起作用,但您可以针对该用例扩展此代码,或者安全地假设普通 Outlook 用户将手粘在鼠标上。

    【讨论】:

      【解决方案2】:

      好的,我解决了问题,

      问题在于自定义任务窗格并不总是从 Outlook 中获取 fucos。

      所以,每当所有窗格都有“onclick”时,我都会引发一个事件,然后强制窗格处于焦点。

      【讨论】:

      • 你是怎么做到的?你能发布一些代码吗?我遇到了同样的问题,但我做的没有任何帮助。
      • 是的,你是怎么做到的?
      【解决方案3】:

      事实证明这是一个很容易解决的问题。

      随便写

      class MyBrowser : WebBrowser {}
      

      然后使用 MyBrowser 而不是 .NET。

      【讨论】:

      • 这很奇怪。为了确定,我多次尝试了这种方法。这也完全没有意义,现在仍然没有。
      【解决方案4】:

      花了很多时间试图让它在 Outlook v16.0.13801.20288 中工作,上面对我不起作用。我最终得到了这个工作代码。

      创建一个用户控件并将您的网络浏览器控件添加到其中,然后自定义 .cs,如下所示

              private void CreateTaskPane() {
                  MyWinFormUserControl webBrowser = new MyWinFormUserControl();
                  webBrowser.webBrowser3.Url = new Uri("https://google.com");
                  
                  webBrowser.webBrowser3.Width = 500;
                  webBrowser.webBrowser3.Dock = DockStyle.Fill;
                  webBrowser.webBrowser3.Visible = true;
      
                  webBrowser.Width = 500;
                  webBrowser.Dock = DockStyle.Fill;
                  webBrowser.Visible = true;
                  
                  this.CRMTaskPaneControl = CustomTaskPanes.Add(webBrowser, "My App");
      
                  
                  //Components.WebViewContainerWPFUserControl webView = (Components.WebViewContainerWPFUserControl)_eh.Child;
                  //webView.webview.Source = new Uri("https://localhost:3000");
      
                  this.CRMTaskPaneControl.Width = 500;
                  System.Windows.Forms.Application.DoEvents();
                  this.CRMTaskPaneControl.Control.Focus();
                  this.CRMTaskPane.Visible = true;      
              }
          public partial class MyWinFormUserControl : UserControl
              {
                  public WebBrowser webBrowser3;
                  public System.Windows.Forms.WebBrowser webBrowser1;
                  public MyWinFormUserControl()
                  {
                      InitializeComponent();
                  }
          
                  private void InitializeComponent()
                  {
                      this.webBrowser3 = new System.Windows.Forms.WebBrowser();
                      this.SuspendLayout();
          
                      // 
                      // webBrowser3
                      // 
                      this.webBrowser3.Dock = System.Windows.Forms.DockStyle.Fill;
                      this.webBrowser3.Location = new System.Drawing.Point(0, 0);
                      this.webBrowser3.MinimumSize = new System.Drawing.Size(20, 20);
                      this.webBrowser3.Name = "webBrowser3";
                      this.webBrowser3.Size = new System.Drawing.Size(500, 749);
                      this.webBrowser3.TabIndex = 0;
                      this.webBrowser3.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser3_DocumentCompleted);
                      // 
                      // MyWinFormUserControl
                      // 
                      this.Controls.Add(this.webBrowser3);
                      this.Name = "MyWinFormUserControl";
                      this.Size = new System.Drawing.Size(500, 749);
                      this.Load += new System.EventHandler(this.MyWinFormUserControl_Load);
                      this.ResumeLayout(false);
          
                  }
          
                  void webBrowser3_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
                  {
                      HtmlDocument doc;
                      doc = webBrowser3.Document;
                      doc.Click += doc_Click;
                  }
          
                  void doc_Click(object sender, HtmlElementEventArgs e)
                  {
                      this.Focus();  // force user control to have the focus
                      HtmlElement elem = webBrowser3.Document.GetElementFromPoint(e.ClientMousePosition);
                      elem.Focus(); // then let the clicked control to have focus
                  }
          
                  private void MyWinFormUserControl_Load(object sender, EventArgs e)
                  {
                      //Control loaded
                  }
             
      

      【讨论】:

        猜你喜欢
        • 2012-02-12
        • 1970-01-01
        • 2015-01-03
        • 2012-02-05
        • 1970-01-01
        • 1970-01-01
        • 2014-10-22
        • 2011-06-15
        • 1970-01-01
        相关资源
        最近更新 更多