Focus issue with Custom Task Pane and WebBrowser Control in Outlook 2010/2016 - vsto

I have Outlook Plugin (using VSTO .net) which opens HTML5 form in the custom task pane of outlook.
Issue: Ctrl + A, TAB events are not working with HTML native controls like Text area after clicking on any outlook fields.
For example I open meeting/email window with my form and then try to write anything in the text area and then press Ctrl + A it works fine. But now If i click on any outlook native fields and then go back to html form text area I cannot do Ctrl + A as well as TAB key is also not working. However, I am able to write any text in that text area.
This issue has been reported to below msdn forum as well and workaround has been provide however, that can have potential issues with some controls like dropdown.
https://social.msdn.microsoft.com/Forums/en-US/0e411bc7-1dba-4a22-86a6-20529e4fe8ea/focus-problems-with-task-pane-and-webcontrol-in-outlook?forum=outlookdev
For ease adding workaround to fix this issue here:
void webBrowser1_DocumentCompleted(object sender,
System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
HtmlDocument doc;
doc = webBrowser1.Document;
doc.Click += doc_Click;
}
void doc_Click(object sender, HtmlElementEventArgs e)
{
this.Focus(); // force user control to have the focus
HtmlElement elem =
webBrowser1.Document.GetElementFromPoint(e.ClientMousePosition);
elem.Focus(); // then let the clicked control to have focus
}
I though this issue will be only limited to outlook 2010 but it's still there with outlook 2016.
Please note I have verified this behaviour with WinForm and WebBrowser control and it works fine there. Only issue is with Outlook.
Do anyone else has faced this issue before and is there any proper fix ?
Please refer link provided above which has youtube link to understand issue exactly.
thanks for your help.

Hosting a web browser inside any Office application is really a bad idea. Even various issues remain in all Office and .NET Framework versions caused by a partial incompatibility of the WPF core and Office GUI.
As a workaround you may consider re-creating the GUI using Windows forms controls.

Related

Visual Basic : How to Block all message boxes, popups and alert dialog

I am making a webbrowser using VB 2010, and I often see popups regarding script errors or advertisement when browsing. I want to disable all message boxes and script error boxes too. I do not want to stop or block scripts from running, I want browser to continue running them but not to show the popup alerts.
WebBrowser1.silent = True isn't working
Thanks in advance
You have tagged this as VB.NET, which I believe is incorrect. In .NET you would use webBrowser.ScriptErrorsSuppressed = true as shown here: Disable JavaScript error in WebBrowser control
The Silent property is available on the ActiveX web browser control in VB6 and probably VBA (?). I believe there is a problem with setting Silent to true there, because it gets set back to false at run time whenever the control is loaded. There is an example on how to work around that by using a timer control, which is available here: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=43907&lngWId=1

Coded UI Test Fails to find Wpf Popup Window controls

I am trying to automate a ribbon control in power point. In that ribbon there are popup windows which contains settings information, when I try to automation those setting popup windows using Coded UI, I got error message like "the control cannot be located playback fail to find control with give search properties", But Coded UI can find the popup window but it fails to find any controls inside it.I have already tried with
SearchConfiguration.AlwaysSearch and setfocus()
Does any one have solutions, it will be very helpful for me!
Find the parent object, i.e the popup window, and enumerate through the children objects manually if codedUI is not able to locate the objects.
IEnumerator<UITestControl> appt = uiMainWindowControl.GetChildren().GetEnumerator();

Word Add-in - find if dialog has focus?

I am writing a word add-in in VB .NET (using Add-in Express, but I don't think that's relevant).
I have created shortcuts, but I only want them to take effect if the document itself is in focus, not a dialog - for example, "Find and replace" or any other.
How do I determine if a dialog has focus?
The "Selection" property of the application points to the selection in the document, even if a dialog is currently selected. I can't find any "HasFocus"-equivalent property anywhere either. I'm running out of ideas :o)
Thanks!
This workaround worked for me:
My add-in keeps a reference to the handle of the most recently activated Word window, by using the GetActiveWindow API during the WindowActivate event of the Word application. This is necessary since, up until Office 2013, the Window object does not expose a handle property.
When a shortcut is triggered, I compare that to the handle of the currently active window, using the same API. If they don't match, I simply don't proceed :o)

Why does using 'Range.ImportFragment' followed by 'ActiveDocument.WordOpenXML' cause a crash?

I am using MS Word 2013. I have created a very simple VSTO 2013 Word Add-in project. To this project I have added a Ribbon (Designer version rather than XML), to which I have added a Button.
The Button has a Click event as follows:
private void button1_Click(object sender, RibbonControlEventArgs e)
{
var app = Globals.ThisAddIn.Application;
app.Selection.Range.ImportFragment("PathToAnotherWordDocument");
var openXML = app.ActiveDocument.WordOpenXML;
}
I then 'F5' to build and start the Add-in. Once word has started, I click on the button.
This causes Word to crash (it is Word itself crashing, not the Add-in).
The file located at PathToAnotherWordDocument is a simple Word Document containing a single paragraph with a couple of words.
If I step through the code everything works fine until I reach the app.ActiveDocument.WordOpenXML line. As soon as I step onto this, the crash happens.
It also happens if I examine this property in the Watch Window, i.e. I scroll down the list of properties for 'app.AtiveDocument' and, as soon as WordOpenXML is in view, Word crashes. All other properties in the Watch Window appear to be fine.
If I comment out the offending line, leaving just the ImportFragment statement then I can continue to use Word just fine. I see the words from the other Word Document have indeed been imported and I can continue to edit without any problems.
Why is this happening? How can I stop it from happening?
EDIT
I have worked out how to stop it from happening: if I assign the app.ActiveDocument.Content.WordOpenXML property to a variable first, the app.ActiveDocument.WordOpenXML property then magically starts working again.
Although this is a solution to my immediate issue, I would still like to know why the crash happens if I access the Document's WordOpenXML property directly.

How do I get the item I right-clicked on in an addin for Outlook 2003?

I've got a great MS Outlook 2003 addin going that adds some features to the context menu. What I am lacking is the ability to get the item I've right-clicked on.
So, in .NET (I'm writing in VB.NET but I know C# as well), how would I grab the item I've right-clicked on? I only want to show this particular context menu addition when I'm right-clicking on an email item, and then do something with that item.
I've already got the menu added and the event firing when I click on my custom buttons, I just need to know how to get the object that is under the cursor in addition to the work I do when clicked.
Thanks for your help.
Try this (using C#):
foreach (MailItem mail in Application.ActiveExplorer().Selection)
{
// ...
}