none
Windows Forms is going in background, after alt+tabbing it is displaying on top RRS feed

  • Question

  • My application is combination of WPF and Winforms.
    Displaying a windows form in the thread process without blocking the code, but the form is going to the background.
    In the Form handle event the handle value is zero.

    Form should be display on the top of the WPF Window. 

    I have tried using pinvoke methods like (FindWindowA,SetForeGroundWindow etc.,)

    this.Focus();
    this.Activate();
    this.BringFront();

    above all the three lines executed in shown,handle, activated event but also it also going in background. 

    public partial class MainWindow : Window{public MainWindow()

    {    

    InitializeComponent();            

    Thread processPostScanThread = new Thread(() => ProcessThreadScannedFile("test"));

    processPostScanThread.SetApartmentState(ApartmentState.STA);            

    processPostScanThread.Start();           

    }

    private object ProcessThreadScannedFile(string p1)

    {

    win_form sc = new win_form ();   

    Task.Run(() => sc.ShowDialog()); 

    return true;

    }

    }

    MainWindow = WPF window

    win_form = Windows form

    Saturday, September 21, 2019 6:52 AM

All replies

  • Hi,

    Do you want to display the WPF window at the top?try the code:

    this.Topmost = true;

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 23, 2019 5:42 AM
    Moderator
  • Hello Alex,

    I want to display windows form on top of the WPF Window.

    Monday, September 23, 2019 7:05 AM
  • Hello Alex,

    I want to display windows form on top of the WPF Window.

    Hi,

     sc.TopMost = true;

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 23, 2019 7:49 AM
    Moderator