⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wizardcontrol.cs

📁 Magic Library 1.7,有说明文档
💻 CS
📖 第 1 页 / 共 4 页
字号:

            return ret;
        }

        protected bool ShouldShowCancel()
        {
            bool ret = false;

            switch(_showCancel)
            {
                case Status.No:
                    break;
                case Status.Yes:
                    ret = true;
                    break;
                case Status.Default:
                    switch(_profile)
                    {
                        case Profiles.Install:
                            // Must have at least one page
                            if (_tabControl.SelectedIndex != -1)
                            {
                                // Cannot 'Cancel' on the last page of an Install
                                if (_tabControl.SelectedIndex < (_tabControl.TabPages.Count - 1))
                                    ret = true;
                            }
                            break;
                        case Profiles.Configure:
                            ret = true;
                            break;
                        case Profiles.Controller:
                            ret = true;
                            break;
                    }
                    break;
            }

            return ret;
        }

        protected bool ShouldEnableCancel()
        {
            bool ret = false;

            switch(_enableCancel)
            {
                case Status.No:
                    break;
                case Status.Yes:
                    ret = true;
                    break;
                case Status.Default:
                    ret = true;
                    break;
            }

            return ret;
        }

        protected bool ShouldShowUpdate()
        {
            bool ret = false;

            switch(_showUpdate)
            {
                case Status.No:
                    break;
                case Status.Yes:
                    ret = true;
                    break;
                case Status.Default:
                    switch(_profile)
                    {
                        case Profiles.Install:
                            break;
                        case Profiles.Configure:
                            break;
                        case Profiles.Controller:
                            ret = true;
                            break;
                    }
                    break;
            }

            return ret;
        }

        protected bool ShouldEnableUpdate()
        {
            bool ret = false;

            switch(_enableUpdate)
            {
                case Status.No:
                    break;
                case Status.Yes:
                    ret = true;
                    break;
                case Status.Default:
                    ret = true;
                    break;
            }

            return ret;
        }

        protected bool ShouldEnableHelp()
        {
            bool ret = false;

            switch(_enableCancel)
            {
                case Status.No:
                    break;
                case Status.Yes:
                    ret = true;
                    break;
                case Status.Default:
                    ret = true;
                    break;
            }

            return ret;
        }

        protected bool ShouldShowHelp()
        {
            bool ret = false;

            switch(_showUpdate)
            {
                case Status.No:
                    break;
                case Status.Yes:
                    ret = true;
                    break;
                case Status.Default:
                    break;
            }

            return ret;
        }

        protected void LeaveFullPage()
        {
            _panelTop.Show();
            _tabControl.Top = _panelTop.Height;
            _tabControl.Height = _panelBottom.Top - _panelTop.Height - 1;
        }
        
        protected void EnterFullPage()
        {
            _panelTop.Hide();
            _tabControl.Top = 0;
            _tabControl.Height = _panelBottom.Top - 1;
        }

        protected void OnTabSelectionChanged(object sender, EventArgs e)
        {
            // Update buttons to reflect change
            UpdateControlButtons();
            
            if (_tabControl.SelectedIndex != -1)
            {
                // Get the selected wizard page
                WizardPage wp = _wizardPages[_tabControl.SelectedIndex];
                
                // Should we be presented in full page?
                if (wp.FullPage)
                    EnterFullPage();
                else
                {
                    // Controller profile is not allowed to be outside of FullMode
                    if (_profile != Profiles.Controller)
                        LeaveFullPage();
                }
            }
            else
            {
                // Controller profile is not allowed to be outside of FullMode
                if (_profile != Profiles.Controller)
                    LeaveFullPage();
            }
            
            // Update manual drawn text
            _panelTop.Invalidate();
            
            // Generate raw selection changed event
            OnSelectionChanged(EventArgs.Empty);
            
            // Generate page leave event if currently on a valid page
            if (_selectedPage != null)
            {
                OnWizardPageLeave(_selectedPage);
                _selectedPage = null;
            }
            
            // Remember which is the newly seleced page
            if (_tabControl.SelectedIndex != -1)
                _selectedPage = _wizardPages[_tabControl.SelectedIndex] as WizardPage;
            
            // Generate page enter event is now on a valid page
            if (_selectedPage != null)
                OnWizardPageEnter(_selectedPage);
        }

        protected void OnButtonHelp(object sender, EventArgs e)
        {
            // Fire event for interested handlers
            OnHelpClick(EventArgs.Empty);
        }

        protected void OnButtonClose(object sender, EventArgs e)
        {
            // Fire event for interested handlers
            OnCloseClick(EventArgs.Empty);
        }

        protected void OnButtonFinish(object sender, EventArgs e)
        {
            // Fire event for interested handlers
            OnFinishClick(EventArgs.Empty);
        }

        protected void OnButtonNext(object sender, EventArgs e)
        {
            CancelEventArgs ce = new CancelEventArgs(false);
            
            // Give handlers chance to cancel this action
            OnNextClick(ce);
            
            if (!ce.Cancel)
            {
                // Move to the next page if there is one
                if (_tabControl.SelectedIndex < _tabControl.TabPages.Count - 1)
                    _tabControl.SelectedIndex++;
            }
        }

        protected void OnButtonBack(object sender, EventArgs e)
        {
            CancelEventArgs ce = new CancelEventArgs(false);
            
            // Give handlers chance to cancel this action
            OnBackClick(ce);
            
            if (!ce.Cancel)
            {
                // Move to the next page if there is one
                if (_tabControl.SelectedIndex > 0)
                    _tabControl.SelectedIndex--;
            }
        }

        protected void OnButtonCancel(object sender, EventArgs e)
        {
            // Fire event for interested handlers
            OnCancelClick(EventArgs.Empty);
        }

        protected void OnButtonUpdate(object sender, EventArgs e)
        {
            // Fire event for interested handlers
            OnUpdateClick(EventArgs.Empty);
        }

        protected void OnWizardCleared()
        {
            // Unhook from event handlers for each page
            foreach(WizardPage wp in _tabControl.TabPages)
            {
                wp.FullPageChanged -= new EventHandler(OnWizardFullPageChanged);
                wp.SubTitleChanged -= new EventHandler(OnWizardSubTitleChanged);
                wp.CaptionTitleChanged -= new EventHandler(OnWizardCaptionTitleChanged);
            }
        
            // Reflect change on underlying tab control
            _tabControl.TabPages.Clear();

            // Update buttons to reflect status
            UpdateControlButtons();
        }
        
        protected void OnWizardInserted(int index, object value)
        {
            WizardPage wp = value as WizardPage;
           
           // Monitor property changes
           wp.FullPageChanged += new EventHandler(OnWizardFullPageChanged);
           wp.SubTitleChanged += new EventHandler(OnWizardSubTitleChanged);
           wp.CaptionTitleChanged += new EventHandler(OnWizardCaptionTitleChanged);
        
            // Reflect change on underlying tab control
            _tabControl.TabPages.Insert(index, wp);

            // Update buttons to reflect status
            UpdateControlButtons();
        }
        
        protected void OnWizardRemoved(int index, object value)
        {
            WizardPage wp = _tabControl.TabPages[index] as WizardPage;
        
            // Unhook from event handlers
            wp.FullPageChanged -= new EventHandler(OnWizardFullPageChanged);
            wp.SubTitleChanged -= new EventHandler(OnWizardSubTitleChanged);
            wp.CaptionTitleChanged -= new EventHandler(OnWizardCaptionTitleChanged);

            // Reflect change on underlying tab control
            _tabControl.TabPages.RemoveAt(index);

            // Update buttons to reflect status
            UpdateControlButtons();
        }
        
        protected void OnWizardFullPageChanged(object sender, EventArgs e)
        {
            WizardPage wp = sender as WizardPage;
            
            // Is it the current page that has changed FullPage?
            if (_tabControl.SelectedIndex == _wizardPages.IndexOf(wp))
            {
                // Should we be presented in full page?
                if (wp.FullPage)
                    EnterFullPage();
                else
                {
                    // Controller profile is not allowed to be outside of FullMode
                    if (_profile != Profiles.Controller)
                        LeaveFullPage();
                }
            }
        }

        protected void OnWizardSubTitleChanged(object sender, EventArgs e)
        {
            WizardPage wp = sender as WizardPage;
           
            // Is it the current page that has changed sub title?
            if (_tabControl.SelectedIndex == _wizardPages.IndexOf(wp))
            {
                // Force the sub title to be updated now
                _panelTop.Invalidate();
            }
        }        
        
        protected void OnWizardCaptionTitleChanged(object sender, EventArgs e)
        {
            // Generate event so any dialog containing use can be notify
            if (WizardCaptionTitleChanged != null)
                WizardCaptionTitleChanged(this, e);
        }
    
        protected override void OnResize(EventArgs e)
        {
            this.PerformLayout();
        }

        protected void OnRepaintPanels(object sender, EventArgs e)
        {
            _panelTop.Invalidate();
            _panelBottom.Invalidate();
        }

        protected void OnPaintTopPanel(object sender, PaintEventArgs pe)
        {
            int right = _panelTop.Width;
        
            // Any picture to draw?
            if (_picture != null)
            {
                // Calculate starting Y position to give equal space above and below image
                int Y = (int)((_panelTop.Height - _picture.Height) / 2);
                
                pe.Graphics.DrawImage(_picture, _panelTop.Width - _picture.Width - Y, Y, _picture.Width, _picture.Height);
                
                // Adjust right side by width of width and gaps around it
                right -= _picture.Width + Y + _panelGap;
            }
        
            // Create main title drawing rectangle
            RectangleF drawRectF = new Rectangle(_panelGap, _panelGap, right - _panelGap, _fontTitle.Height);
                                                
            StringFormat drawFormat = new StringFormat();
            drawFormat.Alignment = StringAlignment.Near;
            drawFormat.LineAlignment = StringAlignment.Center;
            drawFormat.Trimming = StringTrimming.EllipsisCharacter;
            drawFormat.FormatFlags = StringFormatFlags.NoClip |
                                     StringFormatFlags.NoWrap;
            
            using(SolidBrush mainTitleBrush = new SolidBrush(_colorTitle))
                pe.Graphics.DrawString(_title, _fontTitle, mainTitleBrush, drawRectF, drawFormat);            
             
            // Is there a selected tab for display?   
            if (_tabControl.SelectedIndex != -1)
            {                
                // Adjust rectangle for rest of the drawing text space
                drawRectF.Y = drawRectF.Bottom + (_panelGap / 2);
                drawRectF.X += _panelGap;
                drawRectF.Width -= _panelGap;
                drawRectF.Height = _panelTop.Height - drawRectF.Y - (_panelGap / 2);

                // No longer want to prevent word wrap to extra lines
                drawFormat.LineAlignment = StringAlignment.Near;
                drawFormat.FormatFlags = StringFormatFlags.NoClip;

                WizardPage wp = _tabControl.TabPages[_tabControl.SelectedIndex] as WizardPage;

                using(SolidBrush subTitleBrush = new SolidBrush(_colorSubTitle))
                    pe.Graphics.DrawString(wp.SubTitle, _fontSubTitle, subTitleBrush, drawRectF, drawFormat);
            }                          
        
            using(Pen lightPen = new Pen(_panelTop.BackColor),
                      darkPen = new Pen(ControlPaint.Light(ControlPaint.Dark(this.BackColor))))
            {
                pe.Graphics.DrawLine(darkPen, 0, _panelTop.Height - 2, _panelTop.Width, _panelTop.Height - 2);
                pe.Graphics.DrawLine(lightPen, 0, _panelTop.Height - 1, _panelTop.Width, _panelTop.Height - 1);
            }            
        }
        
        protected void OnPaintBottomPanel(object sender, PaintEventArgs pe)
        {
            using(Pen lightPen = new Pen(ControlPaint.Light(this.BackColor)),
                      darkPen = new Pen(ControlPaint.Light(ControlPaint.Dark(this.BackColor))))
            {
                pe.Graphics.DrawLine(darkPen, 0, 0, _panelBottom.Width, 0);
                pe.Graphics.DrawLine(lightPen, 0, 1, _panelBottom.Width, 1);
            }            
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -