1

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

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

4

4 回答 4

2

我迟到了几年,但我设法解决了这个问题。解决此问题的最简单方法是确保正确关注输入字段,因此您需要能够在正在加载的任何页面上运行自己的 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 用户将手粘在鼠标上。

于 2013-07-18T13:40:21.397 回答
1

好的,我解决了问题,

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

因此,每当所有窗格都有“onclick”时,我都会引发一个事件,然后强制窗格成为焦点。

于 2010-12-06T17:22:32.950 回答
0

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

写吧

class MyBrowser : WebBrowser {}

然后使用 MyBrowser 而不是 .NET。

于 2013-01-17T11:28:52.083 回答
0

花了很多时间试图让它在 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
            }
       
于 2021-03-15T19:53:35.240 回答