Example #1
0
        public static void AddWindow(Form form, IGwmWindow wnd)
        {
            Debug.Assert(form != null);
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            KeyValuePair <Form, IGwmWindow> kvp = new KeyValuePair <Form, IGwmWindow>(
                form, wnd);

            Debug.Assert(m_vWindows.IndexOf(kvp) < 0);
            m_vWindows.Add(kvp);

            form.TopMost = Program.Config.MainWindow.AlwaysOnTop;
            // Form formParent = form.ParentForm;
            // if(formParent != null) form.TopMost = formParent.TopMost;
            // else { Debug.Assert(false); }

            // form.Font = new System.Drawing.Font(System.Drawing.SystemFonts.MessageBoxFont.Name, 12.0f);

            CustomizeControl(form);

            MonoWorkarounds.ApplyTo(form);

            if (GlobalWindowManager.WindowAdded != null)
            {
                GlobalWindowManager.WindowAdded(null, new GwmWindowEventArgs(
                                                    form, wnd));
            }
        }
        public static void AddWindow(Form form, IGwmWindow wnd)
        {
            if (form == null)
            {
                Debug.Assert(false); throw new ArgumentNullException("form");
            }

            KeyValuePair <Form, IGwmWindow> kvp = new KeyValuePair <Form, IGwmWindow>(
                form, wnd);

            lock (g_oSyncRoot)
            {
                Debug.Assert(g_vWindows.IndexOf(kvp) < 0);
                g_vWindows.Add(kvp);
            }

            // The control box must be enabled, otherwise DPI scaling
            // doesn't work due to a .NET bug:
            // https://connect.microsoft.com/VisualStudio/feedback/details/694242/difference-dpi-let-the-button-cannot-appear-completely-while-remove-the-controlbox-for-the-form
            // https://social.msdn.microsoft.com/Forums/en-US/winforms/thread/67407313-8cb2-42b4-afb9-8be816f0a601/
            Debug.Assert(form.ControlBox);

            form.TopMost = Program.Config.MainWindow.AlwaysOnTop;
            // Form formParent = form.ParentForm;
            // if(formParent != null) form.TopMost = formParent.TopMost;
            // else { Debug.Assert(false); }

            // form.Font = new System.Drawing.Font(System.Drawing.SystemFonts.MessageBoxFont.Name, 12.0f);

            CustomizeForm(form);

            MonoWorkarounds.ApplyTo(form);

            Debug.Assert(!(form is MainForm));             // MainForm calls the following itself
            CustomizeFormHandleCreated(form, true, true);

            if (GlobalWindowManager.WindowAdded != null)
            {
                GlobalWindowManager.WindowAdded(null, new GwmWindowEventArgs(
                                                    form, wnd));
            }
        }