ユーザーコントロールにWebブラウザーを使用して、Outlookアドイン(カスタム作業ウィンドウ)を開発しました。
Webブラウザのテキストボックスに何かを書いているときに、バックスペースまたは削除ボタンの横でうまく機能しているものはすべて、それらのキーを使用できません。何かが足りませんか?
ユーザーコントロールにWebブラウザーを使用して、Outlookアドイン(カスタム作業ウィンドウ)を開発しました。
Webブラウザのテキストボックスに何かを書いているときに、バックスペースまたは削除ボタンの横でうまく機能しているものはすべて、それらのキーを使用できません。何かが足りませんか?
私はパーティーに数年遅れていますが、なんとかこれを修正することができました。これを修正する最も簡単な方法は、入力フィールドに適切なフォーカスが与えられていることを確認することです。そのため、ロードされているページで独自の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と想定)から実行されるコードが含まれています。このコードは、Webページからアドインに戻ることができるように公開されています。
カスタムタスクペインのアドインコードで、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ユーザーがマウスに手を接着すると安全に想定できます。
わかりました、問題を解決しました、
問題は、のカスタム作業ウィンドウが常にOutlookからfucosを取得するとは限らないことです。
そのため、すべてのペインに「onclick」があるたびにイベントを発生させてから、ペインにフォーカスを強制しました。
これは簡単に修正できる問題であることがわかりました。
書くだけ
class MyBrowser : WebBrowser {}
次に、.NETではなくMyBrowserを使用します。
Outlook v16.0.13801.20288でこれを機能させるために多くの時間を費やしましたが、上記は機能しませんでした。私はこの作業コードに行き着きました。
ユーザーコントロールを作成し、それにWebブラウザーコントロールを追加してから、以下のように.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
}