开发者

Outlook add in , text box , delete\backspace not working

开发者 https://www.devze.com 2023-01-22 19:49 出处:网络
I developed an outlook add in (custom task pane), with web browser in the user control. All the things working well be开发者_JAVA百科side the backspace or the delete button when I am writing somethin

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

All the things working well be开发者_JAVA百科side 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?


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.


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.


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
            }
       


Turns out this is an easy issue to fix.

Just write

class MyBrowser : WebBrowser {}

Then use MyBrowser instead of the .NET one.

0

精彩评论

暂无评论...
验证码 换一张
取 消