Application wont show in foreground

Hello

I am using DLL FastReport.Net Standart Edition in my C# dll. This Dll is called in Magis XPA 3.3 application. As anyone expect the dll can open, create, print or export to pdf from template. But my problem is that when i have to open anything(from fastreport studio, Print, or export to pdf form) it will open behind our magis application and behind last focused window. The window can be anything.

So my question is: Do anyone know how to bring the window(Fastreport studio, Print, PDE export, etc.) in foreground(Bring focus on the window so its first to see for user)?

Comments

  • Hello!

    To resolve your issue, please use the following code:

    public sealed class Win32WindowOwner : System.Windows.Forms.IWin32Window
    {
    public IntPtr Handle { get; }
    public Win32WindowOwner(IntPtr hwnd) => Handle = hwnd;
    }
    
    var owner = new Win32WindowOwner(magicMainWindowHwnd); // or GetForegroundWindow()
    report.Design(owner);
    // or when displaying a preview:
    report.ShowPrepared(modal: true, owner: owner);
    

    And if it is difficult to obtain the HWND from Magic XPA, you can temporarily pass Process.GetCurrentProcess().MainWindowHandle (for a single process) or use a Form wrapper { TopMost = true } as the owner at the time of the call.

This discussion has been closed.