|
Imports System.ComponentModel
Imports System.ComponentModel.Design
<DefaultEvent("OnNextUI")> _
Public Class WizardPanel
Inherits System.Windows.Forms.UserControl
'Inherits System.Windows.Forms.Panel
<Browsable(False)> Private m_UIPanels As Panel()
<Browsable(False)> Private m_ActiveUI As Panel
<Browsable(False)> Private m_ActiveUIIndex As Integer
Public Event OnNextUI(ByVal e As OnUIChangeEventArgs)
Public Event OnPrevUI(ByVal e As OnUIChangeEventArgs)
Public Sub New()
MyBase.New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
If m_UIPanels Is Nothing Then
Dim Graph As Graphics = e.Graphics
Dim Fnt As New Font("Verdana", 10)
Dim Str As String
Dim Rc As Rectangle = New Rectangle(0, 0, Me.Width, Me.Height)
Str = "Wizard Control" + Environment.NewLine
Str += "Author Yasin HINISLIO�LU (yaskil@gmail.com)" + Environment.NewLine + Environment.NewLine
Str += "At Design Time" + Environment.NewLine
Str += "Use UIPanels property to add new user interface" + Environment.NewLine + Environment.NewLine
Str += "Inorder to navigate through your UI, select top most Panel right click and select send to back item to see next panel" + Environment.NewLine + Environment.NewLine
Str += "At Run Time" + Environment.NewLine
Str += "Use NextUI, PreviousUI functions and OnNextUI, OnPrevUI events to change behaviour of your control" + Environment.NewLine + Environment.NewLine
Str += "Do not modify UIPanels property on runtime!!!"
Graph.DrawString(Str, Fnt, Brushes.MistyRose, Rc, Drawing.StringFormat.GenericDefault)
Fnt.Dispose()
End If
End Sub
'add new ui to our ui list
<Browsable(True), ImmutableObject(True)> _
Public Property UIPanels() As Panel()
Get
Return m_UIPanels
End Get
Set(ByVal value As Panel())
If value Is Nothing Then Return
If value.Length <= 0 Then
m_UIPanels = Nothing
Return
End If
m_UIPanels = value
If m_UIPanels IsNot Nothing Then
Me.Controls.Clear()
For Each p As Panel In m_UIPanels
p.Dock = DockStyle.Fill
p.AutoScroll = True
p.BackColor = Color.FromKnownColor(KnownColor.Control)
AddHandler p.Disposed, AddressOf PanelDisposed
Me.Controls.Add(p)
Next
End If
End Set
End Property
'if panel is deleted, remove it from our UI list
Private Sub PanelDisposed(ByVal sender As Object, ByVal e As System.EventArgs)
Dim p As Panel = CType(sender, Panel)
Dim arr As Panel()
Dim k = 0
If m_UIPanels Is Nothing Then Return
ReDim arr(m_UIPanels.Length - 2)
For i As Integer = 0 To m_UIPanels.Length - 1
If m_UIPanels(i) IsNot p Then
arr(k) = m_UIPanels(i)
k += 1
End If
Next
If arr.Length <= 0 Then arr = Nothing
m_UIPanels = arr
End Sub
Public Sub StartWizard()
If m_UIPanels Is Nothing Then Return
m_ActiveUIIndex = 0
m_ActiveUI = m_UIPanels(m_ActiveUIIndex)
m_ActiveUI.BringToFront()
End Sub
Public Sub NextUI()
If m_UIPanels Is Nothing Then Return
Dim e As New OnUIChangeEventArgs(m_ActiveUIIndex, m_ActiveUI)
e.CanMoveNextUI = True
RaiseEvent OnNextUI(e)
If e.CanMoveNextUI Then
m_ActiveUIIndex += 1
If m_ActiveUIIndex >= m_UIPanels.Length Then m_ActiveUIIndex = m_UIPanels.Length - 1
m_ActiveUI = m_UIPanels(m_ActiveUIIndex)
m_ActiveUI.BringToFront()
End If
End Sub
Public Sub PreviosUI()
If m_UIPanels Is Nothing Then Return
Dim e As New OnUIChangeEventArgs(m_ActiveUIIndex, m_ActiveUI)
e.CanMoveNextUI = True
RaiseEvent OnPrevUI(e)
If e.CanMoveNextUI Then
m_ActiveUIIndex -= 1
If m_ActiveUIIndex <= 0 Then m_ActiveUIIndex = 0
m_ActiveUI = m_UIPanels(m_ActiveUIIndex)
m_ActiveUI.BringToFront()
End If
End Sub
End Class
Public Class OnUIChangeEventArgs
Private m_CanMoveNextUI As Boolean
Private m_ActiveUIIndex As Integer
Private m_ActiveUI As Panel
Public Sub New(ByVal ActiveUIIndex As Integer, ByVal ActiveUI As Panel)
m_ActiveUIIndex = ActiveUIIndex
m_ActiveUI = ActiveUI
End Sub
Public Property CanMoveNextUI() As Boolean
Get
Return m_CanMoveNextUI
End Get
Set(ByVal value As Boolean)
m_CanMoveNextUI = value
End Set
End Property
Public ReadOnly Property ActiveUIIndex() As Integer
Get
Return m_ActiveUIIndex
End Get
End Property
Public ReadOnly Property ActiveUI() As Panel
Get
Return m_ActiveUI
End Get
End Property
End Class
|
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.
Yasin has more than 10 years of professional experience. He has several published articles includes graphics programming, robotics and application development in academic resources and national press. He is now working as a software developer for semi-governmental organization in Turkey.