Tab from Form Region

Add-in Express™ Support Service
That's what is more important than anything else

Tab from Form Region
 
Alex Carter




Posts: 40
Joined: 2019-02-21
I have a custom form region set up on new emails. When I tab between the controls in that form region and I reach the last control the focus returns to the first item in the form region. Is this normal behaviour? Ideally I would like it to move to the 'To' box on the email.

Thanks,
Alex
Posted 26 Feb, 2019 10:01:29 Top
Andrei Smolin


Add-in Express team


Posts: 16846
Joined: 2006-05-11
Hello Alex,

We will need some time to answer this question. I expect to have something for you next Monday or Tuesday.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Feb, 2019 04:06:45 Top
Alex Carter




Posts: 40
Joined: 2019-02-21
OK that's perfect thanks Andrei.
Posted 27 Feb, 2019 04:35:17 Top
Alexander Solomenko


Add-in Express team


Posts: 134
Joined: 2009-02-27
Hi Alex,

The point is that by default the native code that manages the controls on the Form region does not know anything about Outlook, and Outlook does not know anything about the Form region. We did not implement this behavior in Add-in Express, but it can be implemented on the add-in's side. Here are a couple of thoughts in this regard. You can override the ProcessCmdKey method on the form and check whether the ActiveControl property or the focused control is the same as the last control in the tab order chain. Then, you set focus to the window handle corresponding to the "To" field in an Outlook inspector by using the SetFocus API function. It this case, the ProcessCmdKey method should return TRUE. To return focus back to the form, you need to set windows hook to track the focus moving between the controls in the Outlook inspector as well as pressing the Tab key.
Regards,
Aleksandr Solomenko
Posted 05 Mar, 2019 05:33:39 Top
Alex Carter




Posts: 40
Joined: 2019-02-21
Morning Alexander,
Thanks for the quick and helpful reply! I have overridden the ProcessCmdKey method on the form and when I get to the last control and continue tabbing I grab the active inspector and pass that to my SetFocus method as below:


    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
        If ActiveControl.Name.Equals(chkEfileComplete.Name) Then
            Dim inspector As Inspector = OutlookAppObj.ActiveInspector
            If inspector IsNot Nothing Then
                eFiles.AddinModule.FocusTo(inspector)
                Marshal.ReleaseComObject(inspector)
            End If
        End If

        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function


Below is my set focus method which doesn't work as expected, it currently creates a new page underneath my form region:

Friend Shared Sub FocusTo(ByVal InspectorOrExplorer As Object, ByVal ControlName As String)
        Dim item As Object = Nothing
        Dim selection As Outlook.Selection = Nothing
        If TypeOf InspectorOrExplorer Is Outlook.Explorer Then
            Try
                ' Explorer.Selection may fire an exception; see below
                selection = CType(InspectorOrExplorer, Outlook.Explorer).Selection
                item = selection.Item(1)
            Catch
            Finally
                If selection IsNot Nothing Then Marshal.ReleaseComObject(selection)
            End Try
        ElseIf TypeOf InspectorOrExplorer Is Outlook.Inspector Then
            Try
                item = CType(InspectorOrExplorer, Outlook.Inspector).CurrentItem
            Catch
            End Try
        End If

        Dim pages As Outlook.Pages
        Dim page As Object
        Dim control As Object

        pages = item.GetInspector.ModifiedFormPages
        page = pages.Add("Message")
        control = page.Controls(ControlName)
        control.SetFocus

        Marshal.ReleaseComObject(item)
    End Sub


I am not entirely sure how to move the focus to the to field, do you have any ideas on this?
Posted 06 Mar, 2019 03:58:54 Top
Alexander Solomenko


Add-in Express team


Posts: 134
Joined: 2009-02-27
Hi Alex,

I'm not sure that your focus setting logic will work. You can check it by ribbon button click.

As I already mentioned, you need to use the Windows API to find the window corresponding to the "To" field in the inspector and simply call the SetFocus function from user32.dll.

To find the desired window, you can use the EnumChildWindows or FindWindow function from user32.dll. The "To" field is a window with the "RichEdit20WPT" class name (you can use the Microsoft Spy ++ utility to view windows). Since there are several windows with this class name, you can get a link to AutomationElement (System.Windows.Automation.AutomationElement.FromHandle ()) and check its name to make sure that is the "To" field.
Regards,
Aleksandr Solomenko
Posted 06 Mar, 2019 08:42:32 Top