c#: show modal window in front of other process window

The toolbox of the product requires tools to be displayed on the main interface in a modal form. Make a note of the code points as a memo.

1、IWin32Window

    internal class Win32Window : IWin32Window
    {
        public Win32Window(IntPtr handle)
        {
            this.Handle = handle;
        }

        public IntPtr Handle
        {
            get;
            private set;
        }
    }

 

2. Form display processing

    static class Program
    {
        ///  <summary> 
        /// The main entry point of the application.
        ///  </summary> 
        [STAThread]
         static  void Main( string [] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault( false );
             var mainForm = new MainForm();
             int h; 
//Here, when adding a form, it is valid to judge
if (args.Length == 0 || ! int .TryParse(args[ 0 ], out h)) Application.Run(mainForm); else { var w = new Win32Window((IntPtr)h); mainForm.ShowDialog(w); } } }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324925704&siteId=291194637