Outlook 添加、文本框、删除\退格键不起作用

发布于 2024-09-30 09:18:18 字数 122 浏览 11 评论 0原文

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

当我在网络浏览器的文本框中写入内容时,退格键或删除按钮旁边的所有功能都运行良好,但我无法使用这些键,我是否遗漏了某些内容?

I developed an outlook add in (custom task pane), with web browser in the user control.

All the things working well beside the backspace or the delete button when I am writing something in text box in the web browser, I can't use those keys, am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

千紇 2024-10-07 09:18:18

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

I am a few years late to the party but I managed to fix this. The easiest way to fix this is to ensure proper focus is given to the input fields, so you will need to be able to run your own javascript on whatever page is being loaded.

The javascript I run on the page is as follows (using 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();
});

the window.external variable contains code run from the plugin (c# or VB I assume) which is exposed so we can interact from web page back to the add-in.

In the add-in code for the custom taskpane set the context of 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;
    }

And a public method for focusing:

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

This worked for me, and I hope it helps others. Although do note that this probably doesn't work if the user keyboard navigates using tab, but you can either extend this code for that use case, or safely assume that the average outlook user will have his hand glued to the mouse.

国际总奸 2024-10-07 09:18:18

好的,我解决了问题,

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

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

Ok I solved the problem ,

The problem is that the custom task pane in not always gets fucos from the outlook.

So, I raised an event every time that there is "onclick" for all the pane, and then forced the pane to be in focus.

还在原地等你 2024-10-07 09:18:18

花了很多时间试图让它在 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
            }
       

spent a lot of time trying to get this working in Outlook v16.0.13801.20288 the above did not work for me. I ended up with this working code.

Create a user control and add your webbrowser control to it then customize the .cs as below

        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
            }
       
谈场末日恋爱 2024-10-07 09:18:18

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

只需编写

class MyBrowser : WebBrowser {}

然后使用 MyBrowser 而不是 .NET 。

Turns out this is an easy issue to fix.

Just write

class MyBrowser : WebBrowser {}

Then use MyBrowser instead of the .NET one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文