Exemplo n.º 1
0
        public virtual DialogResult ShowDialog(MobileRemoteUI parentForm, bool fitToContents)
        {
            // TODO: figure out scaling for this form
            // perhaps have a global xScale and yScale factor

            _inUse = true;

            this.titleBar1.Height = (int)(MobileRemoteUI.ScaleFactor.Height * this.titleBar1.Height);

            if (Platform.IsWindowsMobileStandard)
            {
                this.Dock = DockStyle.Fill;
            }
            else
            {
                this.Height = Math.Min(parentForm.Height, (int)(MobileRemoteUI.ScaleFactor.Height * this.Height));
                this.Width  = Math.Min(parentForm.Width - _widthPadding, (int)(MobileRemoteUI.ScaleFactor.Width * (this.titleBar1.Width - _widthPadding)));

                this.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
            }

            this.titleBar1.Visible = _showMenuBar;

            if (!_alreadySized)
            {
                _alreadySized = true;
                ScaleWindow(parentForm, fitToContents);
            }

            titleBar1.Text = this.Text;

            using (Graphics gxSrc = parentForm.CreateGraphics())
            {
                Cursor.Current = Cursors.WaitCursor;
                parentForm.SuspendLayout();

                AlphaLayerControl alphaControl = null;
                if (!Platform.IsWindowsMobileStandard)
                {
                    alphaControl = new AlphaLayerControl(gxSrc, parentForm.ClientSize, 50);

                    alphaControl.Location = new Point(0, 0);
                    alphaControl.Size     = parentForm.ClientSize;
                    alphaControl.Anchor   = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;

                    alphaControl.Click += new EventHandler(alphaControl_Click);

                    parentForm.Controls.Add(alphaControl);
                    parentForm.Controls.SetChildIndex(alphaControl, 0);

                    AlphaLayerSet(alphaControl);
                }
                parentForm.Controls.Add(this);
                parentForm.Controls.SetChildIndex(this, 0);

                //parentForm.ResumeLayout(true);

                Cursor.Current = Cursors.Default;

                this.SetFocus();

                try
                {
                    MainMenu previousMenu = null;
                    if (Platform.IsWindowsMobileStandard)
                    {
                        previousMenu = parentForm.Menu;

                        parentForm.Menu = new MainMenu();
                        parentForm.Menu.MenuItems.Add(new MenuItem());
                        parentForm.Menu.MenuItems.Add(new MenuItem());

                        parentForm.Menu.MenuItems[0].Text   = "OK";
                        parentForm.Menu.MenuItems[0].Click += new EventHandler(okButton_Click);
                        parentForm.Menu.MenuItems[1].Text   = "Cancel";
                        parentForm.Menu.MenuItems[1].Click += new EventHandler(cancelButton_Click);
                    }
                    try
                    {
                        OnLoad();
                        _isLoaded = true;

                        HookFocus(_contentPanel.Controls);
                        parentForm.ResumeLayout();

                        if (this.IsAnimated)
                        {
                            _timer.Enabled = true;
                        }
                        while (!_waitHandle.WaitOne(20, false))
                        {
                            Application.DoEvents();
                        }
                        _waitHandle.Reset();
                        return(this.DialogResult);
                    }
                    finally
                    {
                        if (null != previousMenu)
                        {
                            parentForm.SuspendLayout();
                            parentForm.Menu = previousMenu;
                            parentForm.ResumeLayout();
                        }
                    }
                }
                finally
                {
                    _isLoaded      = false;
                    _timer.Enabled = false;

                    parentForm.SuspendLayout();
                    parentForm.Controls.Remove(this);

                    if (null != alphaControl)
                    {
                        parentForm.Controls.Remove(alphaControl);
                    }
                    parentForm.ResumeLayout(true);

                    parentForm.FocusActive();
                    OnClosed();

                    _inUse = false;
                }
            }
        }