Closing child form deactivated Excel

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

Closing child form deactivated Excel
 
gjvdkamp




Posts: 56
Joined: 2018-08-28
Hi,

On my MainAddIn I have a property ActiveWorkbookWindow:
 public static Win32Window ActiveWorkbookWindow {
            get {                
                var aw = CurrentInstance.ExcelApp.ActiveWindow;
                var w32 = new Win32Window((IntPtr)aw.Hwnd);
                return w32;
            }
        }


Then I open up a form like this:
 private void adxRibbonButton2_OnClick(object sender, IRibbonControl control, bool pressed) {
            var f = new ChildForm();
            f.Show(ActiveWorkbookWindow);
        }


Then When I close the ChildForm, it moves the focus away from the underlying Excel..

When I have the ChildForm open, and activate another app like Chrome, then back to Excel, the ChildForm is shown on top of Excel again so it seem to have them linked up correctly. Also when I have mulitple Excel windows open, then it will show the Childform on top of the Excel Window that started it.
But when I close the child form, it moves the focus away from the underlying Excel window to another app (say Chrome).

Can you spot what I'm doing wrong?

Here's the Win32Window class that is used:
 public class Win32Window : System.Windows.Forms.IWin32Window {

        IntPtr _windowHandle;
        public Win32Window(IntPtr windowHandle) {
            _windowHandle = windowHandle;
        }

        public IntPtr Handle {
            get { return _windowHandle; }
        }
    }
Posted 09 Jan, 2023 05:06:50 Top
gjvdkamp




Posts: 56
Joined: 2018-08-28
It seems to be caused by a save changes dialog that is shown in ChildForm_FormClosing event. When I remove that it does close correctly. Don;t think that's your problem (although you're free to answer of course). How do I close this question?
Posted 09 Jan, 2023 11:45:29 Top