Click here to Skip to main content
15,900,714 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

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;
     }
   }


Note:
MainWindow = WPF window
win_form = Windows form

What I have tried:

Quote:
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.
Posted
Updated 20-Sep-19 22:45pm
Comments
[no name] 21-Sep-19 9:40am    
Trying to run a modal dialog asynchronously? You need to make up your mind what you want to do.
Member 14047666 23-Sep-19 3:06am    
yes i am trying to run in async

1 solution

 
Share this answer
 
Comments
Member 14047666 21-Sep-19 4:52am    
If i defined the TopMost property then form will be always on top irrespective of any window.
RickZeeland 21-Sep-19 4:59am    
Yep, this should only be used for temporary dialogs and such :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900