Click here to Skip to main content
15,881,172 members
Articles / Desktop Programming / Windows Forms
Tip/Trick

Set Owner of a WPF Window to a Form

Rate me:
Please Sign up or sign in to vote.
5.00/5 (17 votes)
28 Nov 2011CPOL 44.8K   4   3
Set Owner of a WPF Window to a Form
Use the following method to set the owner of a System.Windows.Window to a System.Windows.Forms.Form:
C#
public static void setOwner(System.Windows.Forms.Form ownerForm, System.Windows.Window window)
        {
            WindowInteropHelper helper = new WindowInteropHelper(window);
            helper.Owner = ownerForm.Handle;
        }


It might be useful when you are developing an application where you are using WinForms and WPF windows together.

Note: The window will appear always in front of its owner, I use this to display tips, for example.

License

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


Written By
Student
Poland Poland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Tokinabo14-May-20 14:55
professionalTokinabo14-May-20 14:55 
awesome!
Questionjust 2 lines !! Pin
Naman Sharma19-Jun-18 21:03
Naman Sharma19-Jun-18 21:03 
QuestionExactly what I was looking for! Pin
morgi_a30-Jan-15 4:53
morgi_a30-Jan-15 4:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.