Click here to Skip to main content
15,891,248 members
Articles / Programming Languages / Visual Basic

GN Wizard Framework

Rate me:
Please Sign up or sign in to vote.
4.73/5 (51 votes)
21 Dec 2006CPOL3 min read 176.4K   1.7K   94  
A simple Wizard framework.
' Copyright And Detail -------------------------------------------------------------------------------------
' Name:     GNWizardFrameWork.WizardTemplate
' Author:   Gary Noble
' Date:     09/01/2006	
'
' Requires: 
'
' Copyright � 2005 Gary Noble
' --------------------------------------------------------------------------------------
'
' A Custom Made wizard Control
'
' --------------------------------------------------------------------------------------
' History:
'        
' --------------------------------------------------------------------------------------           
'   Date        User            Detail
' --------------------------------------------------------------------------------------
'
'   09/01/2006	Gary Noble      Created
'
' --------------------------------------------------------------------------------------
'
'  *********  If You Use This Control Please Give Credit  *********
'
' --------------------------------------------------------------------------------------
' Copyright (c) 2005/6 Gary Noble
' ---------------------------------------------------------------------
'
' Redistribution and use in source and binary forms, with or
' without modification, are permitted provided that the following
' conditions are met:
'
' 1. Redistributions of source code must retain the above copyright
'    notice, this list of conditions and the following disclaimer.
'
' 2. Redistributions in binary form must reproduce the above copyright
'    notice, this list of conditions and the following disclaimer in
'    the documentation and/or other materials provided with the distribution.
'
' 3. The end-user documentation included with the redistribution, if any,
'    must include the following acknowledgment:
'
'  "This product includes software developed by Gary Noble"
'
' Alternately, this acknowledgment may appear in the software itself, if
' and wherever such third-party acknowledgments normally appear.
'
' THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
' INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
' AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
' GARY NOBLE OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
' INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
' BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
' USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
' THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
' (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
' THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'
' ---------------------------------------------------------------------

#Region "Imports"

Imports System
Imports System.ComponentModel.Design.Serialization
Imports System.Collections
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Globalization
Imports System.Reflection
Imports System.Windows.Forms
Imports System.ComponentModel
Imports GNWizardFrameWork

#End Region

Namespace GNWizardFrameWork

    ''' -----------------------------------------------------------------------------
    ''' Project	 : GNWizardFrameWork
    ''' Class	 : Winforms.UIStudio.Controls.Wizard.WizardTemplate
    ''' 
    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' Simple Wizard Control
    ''' </summary>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' 	[G_Noble]	13/03/2006	Created
    ''' </history>
    ''' -----------------------------------------------------------------------------
    <Serializable(), Designer(GetType(WizardTemplateDesigner), GetType(System.ComponentModel.Design.IDesigner)), ToolboxItem(True), ToolboxBitmap(GetType(GNWizardFrameWork.WizardTemplate))> _
    Public Class WizardTemplate

        Inherits System.Windows.Forms.UserControl

#Region "  Public Events  "

        Public Event OnMoveNext(ByVal NextWizPanel As WizardPage)
        Public Event CancelClick()
        Public Event FinishClick()

#End Region

#Region " Windows Form Designer generated code "


        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Initialises A New Instance Of The Control
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' 	[G_Noble]	09/01/2006	Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Sub New()

            MyBase.New()


            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
            ' This draws the control whenever it is resized
            setstyle(ControlStyles.ResizeRedraw, True)

            ' This supports mouse movement such as the mouse wheel
            setstyle(ControlStyles.UserMouse, True)

            '-- This allows the control to be transparent
            '   setstyle(ControlStyles.SupportsTransparentBackColor, True)

            '-- This Allows The Control To be A Container
            setstyle(ControlStyles.ContainerControl, True)

            '-- This Allows The Control To Be Selectable
            setstyle(ControlStyles.Selectable, True)

            ' This helps with drawing the control so that it doesn't flicker
            Me.SetStyle(ControlStyles.DoubleBuffer _
              Or ControlStyles.UserPaint _
              Or ControlStyles.AllPaintingInWmPaint, _
              True)

            '-- This Updates The Styles
            Me.UpdateStyles()



        End Sub

        'UserControl overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.

        '--  The Pictures Used For The Menu Items
        Friend WithEvents LineTop As GNWizardFrameWork.ThreeDLine
        Friend WithEvents ButtonPanel As System.Windows.Forms.Panel
        Friend WithEvents btnFinish As System.Windows.Forms.Button
        Friend WithEvents btnCancel As System.Windows.Forms.Button
        Friend WithEvents btnPrevious As System.Windows.Forms.Button
        Friend WithEvents btnNext As System.Windows.Forms.Button
        Friend WithEvents Headerpanel As System.Windows.Forms.Panel
        Friend WithEvents ThreeDLineTop As GNWizardFrameWork.ThreeDLine
        Friend WithEvents SubHeaderCaption As System.Windows.Forms.Label
        Friend WithEvents HeaderCaption As System.Windows.Forms.Label
        Friend WithEvents ThreeDLineBottom As GNWizardFrameWork.ThreeDLine

        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Me.ButtonPanel = New System.Windows.Forms.Panel
            Me.btnPrevious = New System.Windows.Forms.Button
            Me.btnNext = New System.Windows.Forms.Button
            Me.btnFinish = New System.Windows.Forms.Button
            Me.btnCancel = New System.Windows.Forms.Button
            Me.ThreeDLineBottom = New GNWizardFrameWork.ThreeDLine
            Me.Headerpanel = New System.Windows.Forms.Panel
            Me.ThreeDLineTop = New GNWizardFrameWork.ThreeDLine
            Me.SubHeaderCaption = New System.Windows.Forms.Label
            Me.HeaderCaption = New System.Windows.Forms.Label
            Me.ButtonPanel.SuspendLayout()
            Me.Headerpanel.SuspendLayout()
            Me.SuspendLayout()
            '
            'ButtonPanel
            '
            Me.ButtonPanel.Controls.Add(Me.btnPrevious)
            Me.ButtonPanel.Controls.Add(Me.btnNext)
            Me.ButtonPanel.Controls.Add(Me.btnFinish)
            Me.ButtonPanel.Controls.Add(Me.btnCancel)
            Me.ButtonPanel.Controls.Add(Me.ThreeDLineBottom)
            Me.ButtonPanel.Dock = System.Windows.Forms.DockStyle.Bottom
            Me.ButtonPanel.Location = New System.Drawing.Point(0, 216)
            Me.ButtonPanel.Name = "ButtonPanel"
            Me.ButtonPanel.Size = New System.Drawing.Size(472, 40)
            Me.ButtonPanel.TabIndex = 2
            '
            'btnPrevious
            '
            Me.btnPrevious.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.btnPrevious.FlatStyle = System.Windows.Forms.FlatStyle.System
            Me.btnPrevious.Location = New System.Drawing.Point(224, 8)
            Me.btnPrevious.Name = "btnPrevious"
            Me.btnPrevious.Size = New System.Drawing.Size(75, 24)
            Me.btnPrevious.TabIndex = 1
            Me.btnPrevious.Text = "&Previous"
            '
            'btnNext
            '
            Me.btnNext.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.btnNext.FlatStyle = System.Windows.Forms.FlatStyle.System
            Me.btnNext.Location = New System.Drawing.Point(304, 8)
            Me.btnNext.Name = "btnNext"
            Me.btnNext.Size = New System.Drawing.Size(75, 24)
            Me.btnNext.TabIndex = 0
            Me.btnNext.Text = "&Next"
            '
            'btnFinish
            '
            Me.btnFinish.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.btnFinish.FlatStyle = System.Windows.Forms.FlatStyle.System
            Me.btnFinish.Location = New System.Drawing.Point(384, 8)
            Me.btnFinish.Name = "btnFinish"
            Me.btnFinish.Size = New System.Drawing.Size(75, 24)
            Me.btnFinish.TabIndex = 7
            Me.btnFinish.Text = "&Finish"
            '
            'btnCancel
            '
            Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System
            Me.btnCancel.Location = New System.Drawing.Point(8, 8)
            Me.btnCancel.Name = "btnCancel"
            Me.btnCancel.TabIndex = 8
            Me.btnCancel.Text = "&Cancel"
            '
            'ThreeDLineBottom
            '
            Me.ThreeDLineBottom.BackColor = System.Drawing.SystemColors.Control
            Me.ThreeDLineBottom.Dock = System.Windows.Forms.DockStyle.Top
            Me.ThreeDLineBottom.HeaderText = ""
            Me.ThreeDLineBottom.LineStyle = System.Windows.Forms.Border3DStyle.Etched
            Me.ThreeDLineBottom.Location = New System.Drawing.Point(0, 0)
            Me.ThreeDLineBottom.Name = "ThreeDLineBottom"
            Me.ThreeDLineBottom.Size = New System.Drawing.Size(472, 12)
            Me.ThreeDLineBottom.Spacing = 0
            Me.ThreeDLineBottom.TabIndex = 4
            '
            'Headerpanel
            '
            Me.Headerpanel.BackColor = System.Drawing.Color.White
            Me.Headerpanel.Controls.Add(Me.ThreeDLineTop)
            Me.Headerpanel.Controls.Add(Me.SubHeaderCaption)
            Me.Headerpanel.Controls.Add(Me.HeaderCaption)
            Me.Headerpanel.Dock = System.Windows.Forms.DockStyle.Top
            Me.Headerpanel.Location = New System.Drawing.Point(0, 0)
            Me.Headerpanel.Name = "Headerpanel"
            Me.Headerpanel.Size = New System.Drawing.Size(472, 56)
            Me.Headerpanel.TabIndex = 3
            Me.Headerpanel.Visible = False
            '
            'ThreeDLineTop
            '
            Me.ThreeDLineTop.Dock = System.Windows.Forms.DockStyle.Bottom
            Me.ThreeDLineTop.HeaderText = ""
            Me.ThreeDLineTop.LineStyle = System.Windows.Forms.Border3DStyle.Etched
            Me.ThreeDLineTop.Location = New System.Drawing.Point(0, 54)
            Me.ThreeDLineTop.Name = "ThreeDLineTop"
            Me.ThreeDLineTop.Size = New System.Drawing.Size(472, 2)
            Me.ThreeDLineTop.Spacing = 0
            Me.ThreeDLineTop.TabIndex = 3
            '
            'SubHeaderCaption
            '
            Me.SubHeaderCaption.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.SubHeaderCaption.AutoSize = True
            Me.SubHeaderCaption.BackColor = System.Drawing.Color.Transparent
            Me.SubHeaderCaption.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.SubHeaderCaption.Location = New System.Drawing.Point(32, 32)
            Me.SubHeaderCaption.Name = "SubHeaderCaption"
            Me.SubHeaderCaption.Size = New System.Drawing.Size(0, 16)
            Me.SubHeaderCaption.TabIndex = 1
            '
            'HeaderCaption
            '
            Me.HeaderCaption.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.HeaderCaption.AutoSize = True
            Me.HeaderCaption.BackColor = System.Drawing.Color.Transparent
            Me.HeaderCaption.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.HeaderCaption.Location = New System.Drawing.Point(8, 8)
            Me.HeaderCaption.Name = "HeaderCaption"
            Me.HeaderCaption.Size = New System.Drawing.Size(0, 18)
            Me.HeaderCaption.TabIndex = 0
            '
            'WizardTemplate
            '
            Me.Controls.Add(Me.ButtonPanel)
            Me.Controls.Add(Me.Headerpanel)
            Me.Name = "WizardTemplate"
            Me.Size = New System.Drawing.Size(472, 256)
            Me.ButtonPanel.ResumeLayout(False)
            Me.Headerpanel.ResumeLayout(False)
            Me.ResumeLayout(False)

        End Sub

#End Region

#Region "  Declarations  "


        Private WithEvents m_colPages As WizardPageCollection = New WizardPageCollection

        Private m_SelectedItem As WizardPage = Nothing
        Private m_lStartItem As Integer
        Private m_lCurrentItem As Integer
        Private m_HeaderPicture As Image
        Private m_HeaderSmallPicture As Image
        Private m_HeaderTitle As String = "GN Wizard"
        Private m_HeaderSubHeading As String = "Please add a panel"


#End Region

#Region "  WizardPages Collection Events  "

        ' All These procedures are called from the Panel Collection
        ' See The CollectionClass for Detail

        '-- Detail Please Read!
        '-----------------------------------------------------------------------------------------------------------
        '   Name:       Changed
        '   NameSpace:  
        '   Purpose:    Tells The Control That A Part Of A WizardPage Has Been Changed
        '   Requires:   
        '   Assumes:    WizardPage
        '-----------------------------------------------------------------------------------------------------------
        '   History:    Version     Data                                        User            Date
        '-----------------------------------------------------------------------------------------------------------
        '               1.0         Initial Version                             Gary Noble      20 Sept 2005
        '-----------------------------------------------------------------------------------------------------------
        Private Sub m_colPages_Changed(ByVal sender As Object, ByVal e As System.EventArgs) Handles m_colPages.Changed

            Try

                DisplayCurrentPage()

                Me.UpdateDesignTimeComponents()

                Invalidate()

            Catch ex As Exception

                Throw ex
            End Try

        End Sub

        '-- Detail Please Read!
        '-----------------------------------------------------------------------------------------------------------
        '   Name:       Added
        '   NameSpace:  
        '   Purpose:    Tells The Control An Item has Been Added, Also Attaches The WizardPage Panel To This Control
        '   Requires:   
        '   Assumes:    WizardPage
        '-----------------------------------------------------------------------------------------------------------
        '   History:    Version     Data                                        User            Date
        '-----------------------------------------------------------------------------------------------------------
        '               1.0         Initial Version                             Gary Noble      20 Sept 2005
        '-----------------------------------------------------------------------------------------------------------
        Private Sub m_colPages_Added(ByVal sender As Object) Handles m_colPages.Added

            Try

                If Not sender Is Nothing Then

                    '-- Add The Page To The Control
                    If Not Me.Controls.Contains(sender) Then Me.Controls.Add(sender)

                    If designmode Then

                        Me.m_lCurrentItem = Pages.IndexOf(sender)

                    End If

                    DisplayCurrentPage()

                End If


            Catch ex As Exception

                Throw New Exception(ex.Message, ex)

            End Try

            Invalidate()
        End Sub

        '-----------------------------------------------------------------------------------------------------------
        '   Name:       ItemRemoved
        '   NameSpace:  
        '   Purpose:    Sets The Next Available Item As Selected And Raises The ItemRemoved Event
        '   Requires:   
        '   Assumes:   WizardPage
        '-----------------------------------------------------------------------------------------------------------
        '   History:    Version     Data                                        User            Date
        '-----------------------------------------------------------------------------------------------------------
        '               1.0         Initial Version                             Gary Noble      20 Sept 2005
        '-----------------------------------------------------------------------------------------------------------
        Private Sub m_colPages_ItemRemoved(ByVal sender As Object, ByVal e As System.EventArgs) Handles m_colPages.ItemRemoved

            Dim _objPane As WizardPage

            _objPane = DirectCast(sender, WizardPage)

            Try

                If _objPane.Visible Then _objPane.Visible = False

                If Not _objPane Is Nothing Then

                    Me.Controls().Remove(_objPane)

                End If

                Me.Refresh()

            Catch ex As Exception

            End Try

        End Sub



        '-- Detail Please Read!
        '-----------------------------------------------------------------------------------------------------------
        '   Name:       UpdateDesignTimeComponents
        '   NameSpace:  
        '   Purpose:    Updates The UI at Design Time
        '   Requires:   
        '   Assumes:    
        '-----------------------------------------------------------------------------------------------------------
        '   History:    Version     Data                                        User            Date
        '-----------------------------------------------------------------------------------------------------------
        '               1.0         Initial Version                             Gary Noble      20 Sept 2005
        '-----------------------------------------------------------------------------------------------------------
        Friend Sub UpdateDesignTimeComponents()

            If DesignMode Then

                Dim c As IComponentChangeService = DirectCast(getservice(GetType _
                (IComponentChangeService)), IComponentChangeService)

                c.OnComponentChanged(Me, Nothing, Nothing, Nothing)

                c = Nothing

                Dim _SelectionService As ISelectionService
                Dim _aItems As ArrayList

                If Not SelectedPane Is Nothing Then
                    _SelectionService = DirectCast(GetService(GetType(ISelectionService)), ISelectionService)
                    _aItems = New ArrayList
                    _aItems.Add(SelectedPane)
                    _SelectionService.SetSelectedComponents(_aItems)
                End If

            End If


        End Sub


        Private Sub m_colPages_CancelButtonStateChange(ByVal sender As Object, ByVal bEnabled As Boolean) Handles m_colPages.CancelButtonStateChange
            If sender Is Me.CurrentPage Then Me.btnCancel.Enabled = bEnabled
            Invalidate()
        End Sub

        Private Sub m_colPages_FinishButtonStateChange(ByVal sender As Object, ByVal bEnabled As Boolean) Handles m_colPages.FinishButtonStateChange
            If sender Is Me.CurrentPage Then Me.btnFinish.Enabled = bEnabled
            Invalidate()
        End Sub

        Private Sub m_colPages_NextButtonStateChange(ByVal sender As Object, ByVal bEnabled As Boolean) Handles m_colPages.NextButtonStateChange
            If sender Is Me.CurrentPage Then Me.btnNext.Enabled = bEnabled
            Invalidate()
        End Sub

        Private Sub m_colPages_PreviousButtonStateChange(ByVal sender As Object, ByVal bEnabled As Boolean) Handles m_colPages.PreviousButtonStateChange
            If sender Is Me.CurrentPage Then Me.btnPrevious.Enabled = bEnabled
            Invalidate()
        End Sub

#End Region

#Region "  Properties  "

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Determines what page you want the Wizard to start at
        ''' </summary>
        ''' <value></value>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' 	[G_Noble]	15/03/2006	Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        <Description("Determines what page you want the Wizard to start at")> _
        Public Property StartItemIndex() As Integer

            Get

                Return m_lStartItem

            End Get

            Set(ByVal Value As Integer)

                m_lStartItem = Value

                '-- Make sure we do not go over or under the page count
                If m_lStartItem >= Pages.Count Then m_lStartItem = Pages.Count

                If m_lStartItem < 0 Then m_lStartItem = 0

                m_lCurrentItem = m_lStartItem

                DisplayCurrentPage()

                Invalidate()

            End Set

        End Property
        '-- Detail Please Read!
        '-----------------------------------------------------------------------------------------------------------
        '   Name:       HeaderImage
        '   NameSpace:  
        '   Purpose:    Displays A Image For Interior Pages
        '   Requires:   
        '   Assumes:    
        '-----------------------------------------------------------------------------------------------------------
        '   History:    Version     Data                                        User            Date
        '-----------------------------------------------------------------------------------------------------------
        '               1.0         Initial Version                             Gary Noble      20 Sept 2005
        '-----------------------------------------------------------------------------------------------------------
        <Description("Sets the Banner image for Interior Pages")> _
                Public Property BannerImage() As Image

            Get

                Return Me.Headerpanel.BackgroundImage

            End Get

            Set(ByVal Value As Image)

                Me.Headerpanel.BackgroundImage = Value

                Invalidate()

            End Set

        End Property

        '-- Detail Please Read!
        '-----------------------------------------------------------------------------------------------------------
        '   Name:       Pages
        '   NameSpace:  
        '   Purpose:    Wizard Panel Collection
        '   Requires:   
        '   Assumes:    
        '-----------------------------------------------------------------------------------------------------------
        '   History:    Version     Data                                        User            Date
        '-----------------------------------------------------------------------------------------------------------
        '               1.0         Initial Version                             Gary Noble      20 Sept 2005
        '-----------------------------------------------------------------------------------------------------------
        <DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
        Description("Wizard page collection")> _
          Public Property Pages() As WizardPageCollection

            Get

                Return IIf(m_colPages Is Nothing, New WizardPageCollection, m_colPages)

            End Get

            Set(ByVal Value As WizardPageCollection)

                m_colPages = Value

                Me.Invalidate()

            End Set

        End Property

        '-- Detail Please Read!
        '-----------------------------------------------------------------------------------------------------------
        '   Name:       CurrentPage
        '   NameSpace:  
        '   Purpose:    Returns the active WizardPage
        '   Requires:   
        '   Assumes:    
        '-----------------------------------------------------------------------------------------------------------
        '   History:    Version     Data                                        User            Date
        '-----------------------------------------------------------------------------------------------------------
        '               1.0         Initial Version                             Gary Noble      20 Sept 2005
        '-----------------------------------------------------------------------------------------------------------
        <Description("Returns the viewed page")> _
                Public ReadOnly Property CurrentPage() As WizardPage

            Get

                Return Pages(m_lCurrentItem)

            End Get

        End Property

        '-- Detail Please Read!
        '-----------------------------------------------------------------------------------------------------------
        '   Name:       SelectedItem
        '   NameSpace:  
        '   Purpose:    Determins The Selected Item  
        '   Requires:   
        '   Assumes:    WizardPage
        '-----------------------------------------------------------------------------------------------------------
        '   History:    Version     Data                                        User            Date
        '-----------------------------------------------------------------------------------------------------------
        '               1.0         Initial Version                             Gary Noble      20 Sept 2005
        '-----------------------------------------------------------------------------------------------------------
        <DefaultValue(GetType(WizardPage), Nothing)> _
        Friend Property SelectedPane() As WizardPage

            Get
                Return Pages(m_lCurrentItem)
            End Get

            Set(ByVal Value As WizardPage)
                Try

                    m_SelectedItem = Value

                Catch ex As Exception

                End Try

                Invalidate()

            End Set

        End Property

#End Region

#Region "  Subs  "

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Navigates you to the page you want to display
        ''' </summary>
        ''' <param name="Index"></param>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' 	[G_Noble]	15/03/2006	Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Sub GotoPage(ByVal Index As Integer)

            Try

                If Index < 0 Or Index > Pages.Count Then

                    Throw New Exception("No panel with that index exists!")

                Else

                    m_lCurrentItem = Index

                    If m_lCurrentItem >= Pages.Count Then m_lCurrentItem = Pages.Count

                    If m_lCurrentItem < 0 Then m_lCurrentItem = 0

                    DisplayCurrentPage()

                End If

            Catch ex As Exception

            End Try
            Invalidate()

        End Sub


        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' checks the current state of the wizard
        ''' also checks for designmode, so we can edit at design time
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' 	[G_Noble]	21/03/2006	Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub CheckState()

            btnPrevious.Enabled = m_lCurrentItem > 0


            If Designmode Then

                Me.btnNext.Enabled = True
                Me.btnPrevious.Enabled = True
                Me.btnCancel.Enabled = False
                Me.btnFinish.Enabled = False

            Else

                If Pages.Count > 0 Then

                    If Not SelectedPane Is Nothing Then

                        Me.btnFinish.Enabled = SelectedPane.HasFinishButton
                        Me.btnNext.Enabled = SelectedPane.HasNextButton
                        Me.btnPrevious.Enabled = SelectedPane.HasPreviousButton
                        Me.btnCancel.Enabled = SelectedPane.HasCancelButton


                        '-- Update to HasPreviousButton from HasNextButton
                        '-- This Was An Issue Raised By Bill Reinhold
                        '-- Thankyou Bill.
                        If m_lStartItem > 0 Then
                            btnPrevious.Enabled = m_lCurrentItem > m_lStartItem And SelectedPane.HasPreviousButton
                        Else
                            btnPrevious.Enabled = m_lCurrentItem > 0 And SelectedPane.HasPreviousButton
                        End If

                        If btnNext.Enabled Then
                            btnNext.Enabled = m_lCurrentItem <= Pages.Count
                        End If

                    Else

                        Me.btnFinish.Enabled = False
                        Me.btnNext.Enabled = False
                        Me.btnPrevious.Enabled = False
                        Me.btnCancel.Enabled = False

                    End If

                Else

                    Me.btnFinish.Enabled = False
                    Me.btnNext.Enabled = False
                    Me.btnPrevious.Enabled = False
                    Me.btnCancel.Enabled = False

                End If

            End If



        End Sub

#End Region

#Region "  Control Override sub/Functions  "

        '-- Detail Please Read!
        '-----------------------------------------------------------------------------------------------------------
        '   Name:       OnControlAdded (Overrides)
        '   NameSpace:  
        '   Purpose:    Repaints the control
        '   Requires:   
        '   Assumes:    Pages
        '-----------------------------------------------------------------------------------------------------------
        '   History:    Version     Data                                        User            Date
        '-----------------------------------------------------------------------------------------------------------
        '               1.0         Initial Version                             Gary Noble      20 Sept 2005
        '-----------------------------------------------------------------------------------------------------------
        Protected Overrides Sub OnControlAdded(ByVal e As System.Windows.Forms.ControlEventArgs)
            Try

                DisplayCurrentPage()

                Invalidate()

            Catch ex As Exception
                Throw ex
            End Try

        End Sub


        Protected Overrides Sub OnControlRemoved(ByVal e As System.Windows.Forms.ControlEventArgs)


            If e.Control.GetType Is GetType(WizardPage) Then

                If Pages.IndexOf(e.Control) = m_lCurrentItem Then

                    m_lCurrentItem = m_lCurrentItem - 1

                    If m_lCurrentItem < 0 Then m_lCurrentItem = 0

                    Me.DisplayCurrentPage()

                End If

                '-- Remove The control From The Parent form
                If Not FindForm() Is Nothing Then

                    FindForm.Controls.Remove(e.Control)

                End If

                '-- Remove From The Collection
                MyClass.Pages.Remove(e.Control)

                '-- Reset The Design Time Layout
                If Me.DesignMode Then

                    m_lCurrentItem = 0

                    Me.InitLayout()

                End If

                Application.DoEvents()

            End If

        End Sub

        Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
            If Not SelectedPane Is Nothing Then
                SelectedPane.Focus()
            End If
        End Sub

        Protected Overrides Sub InitLayout()

            '-- Check for the startIndex and show 
            m_lCurrentItem = Me.StartItemIndex
            DisplayCurrentPage()
            CheckState()
            Invalidate()

        End Sub


        Protected Overrides Sub Finalize()
            MyBase.Finalize()
        End Sub

#End Region

#Region "  Control Events  "

        Private Sub wizard_EnabledChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.EnabledChanged
            Invalidate()
        End Sub

        Private Sub wizard_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
            DisplayCurrentPage()
            Invalidate()

        End Sub


#End Region

#Region "  Button Events  "

        Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click


            m_lCurrentItem += 1
            If m_lCurrentItem <= Pages.Count - 1 Then

                DisplayCurrentPage()

                RaiseEvent OnMoveNext(Pages(m_lCurrentItem))

                Invalidate()

            Else

                m_lCurrentItem = Pages.Count - 1

                Invalidate()

            End If

        End Sub


        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Gets and Displays The Previous Page
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' 	[G_Noble]	15/03/2006	Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click

            m_lCurrentItem += -1

            If m_lCurrentItem < 0 Then m_lCurrentItem = 0 : Exit Sub

            If m_lCurrentItem < 0 Then m_lCurrentItem = 0

            CheckState()

            Me.DisplayCurrentPage()

            Invalidate()

        End Sub

        Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            RaiseEvent CancelClick()
            Invalidate()
        End Sub

        Private Sub btnFinish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinish.Click
            RaiseEvent FinishClick()
            Invalidate()
        End Sub

        Private Sub btnPrevious_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnPrevious.MouseUp
            If designmode Then btnPrevious.PerformClick()
        End Sub

        Private Sub btnNext_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnNext.MouseUp

            If designmode Then
                btnNext.Select()
                btnNext.PerformClick()
            End If
        End Sub

        Private Sub btnNext_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnNext.MouseDown
            If designmode Then btnNext.Select()
            MyBase.OnMouseDown(e)
        End Sub

        Private Sub btnPrevious_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnPrevious.MouseDown
            If designmode Then btnPrevious.Select()
        End Sub

#End Region


        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Displays The Pag you Want to View
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' 	[G_Noble]	21/03/2006	Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Friend Function DisplayCurrentPage()

            Dim _objPane As WizardPage

            Try

                CheckState()

                If Pages.Count > 0 Then

                    For Each _objPane In Pages

                        '-- Exterior Page config
                        If _objPane.PageStyle = PageStyle.eWPS_Exterior Then

                            Me.Headerpanel.Visible = False

                            _objPane.Location = New Point(0, 0)

                            _objPane.Size = New Size(Width, Height - (Me.ButtonPanel.Height))

                            _objPane.BringToFront()

                        Else

                            _objPane.Location = New Point(0, Headerpanel.Height)

                            _objPane.Size = New Size(Width, Height - (Headerpanel.Height + Me.ButtonPanel.Height))

                        End If

                        _objPane.Visible = CBool(Me.m_lCurrentItem = Pages.IndexOf(_objPane))

                    Next

                    '-- show the Current Page
                    If Not Me.CurrentPage Is Nothing Then

                        _objPane = Me.CurrentPage

                        If _objPane.PageStyle = PageStyle.eWPS_Interior Then

                            Me.Headerpanel.Visible = True

                            Headerpanel.BringToFront()

                            Me.HeaderCaption.Text = _objPane.HeaderCaption

                            Me.SubHeaderCaption.Text = _objPane.SubHeaderCaption

                        End If

                    End If

                Else

                    Me.Headerpanel.Visible = False

                    Me.HeaderCaption.Text = vbNullString

                    Me.SubHeaderCaption.Text = vbNullString

                End If



            Catch ex As Exception

            End Try

        End Function


        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Used To Ammend The DesignTime Verbs
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks>
        ''' This Only Gets Called From The Deigner At Design Time
        ''' </remarks>
        ''' <history>
        ''' 	[G_Noble]	15/03/2006	Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Friend Function InternalItemCount() As Integer
            Try
                If Not Pages Is Nothing Then
                    Return Pages.Count
                Else
                    Return 0
                End If
            Catch ex As Exception
                Throw ex
            End Try

        End Function

        Private Sub btnNext_ChangeUICues(ByVal sender As Object, ByVal e As System.Windows.Forms.UICuesEventArgs) Handles btnNext.ChangeUICues

        End Sub
    End Class


End Namespace



By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


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

Comments and Discussions