a form with navigation

FasFasil

New member
Joined
Mar 6, 2008
Messages
2
Programming Experience
Beginner
hiya all
thanks for reading
i am loking for any hints or codes on how to go about creating a form with navigation to forward & backwards

for example
A Quiz that lets the user go from question 1 to questin 2 with a click of a button
Thanks
 
I would use a set of panels, all stacked on top of each other. Then using an index, when a button's clicked either add one or subtract one from the index (and hide all the panel) then use a select case statement on the index and show the appropriate panel
 
I think I've seen some Wizard control on SourceForge. Maybe could be made to work. Stacking panels makes it very difficult to work in the Designer (personal experience :(), but should work well with a limited number of them.

Maybe you could use a TabControl and hide the tabs (I think that's possible, I might be wrong...) so you can use the Designer easily and decide which to show using the TabPage's name...

Otherwise I'd think about making my own custom control that would work in the Designer. It'd probably use stacked panels internally, but you've got to hide that complexity! Now that I've actually been through the trouble of working without it, I can definitly say it's worth the extra time, especially if your panels look like each other and you have to solve a bug in only one of them (personal experience again... I remember the tester coming back to me saying the invoice label is still plural and the quote label is "invoice"... :() !
 
I'd do this with embedded forms. Essentially the same as Juggalobrotha's idea of using panels, but much easier to work with in the Designer as Stonkie says.

If you want to try it, put four forms in a project, frmMain, Form1, Form2 and Form3. Add a button to Form1, and a button to Form2. In the sample code below, I've included all the form properties that I amend in the Designer.

frmMain code:
VB.NET:
Public Class frmMain

    Public f1 As Form1
    Public f2 As Form2
    Public f3 As form3

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        f1 = New Form1
        f1.BackColor = Color.LightBlue
        f1.TopLevel = False
        f1.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        f1.StartPosition = FormStartPosition.CenterParent
        f1.WindowState = FormWindowState.Maximized
        Me.Controls.Add(f1)
        f1.Show()


        f2 = New Form2
        f2.BackColor = Color.Red
        f2.TopLevel = False
        f2.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        f2.StartPosition = FormStartPosition.CenterParent
        f2.WindowState = FormWindowState.Maximized
        Me.Controls.Add(f2)
        f2.Show()


        f3 = New Form3
        f3.BackColor = Color.Green
        f3.TopLevel = False
        f3.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        f3.StartPosition = FormStartPosition.CenterParent
        f3.WindowState = FormWindowState.Maximized
        Me.Controls.Add(f3)
        f3.show()

    End Sub

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        f1.Size = Me.Size
        f2.Size = Me.Size
        f3.Size = Me.Size
    End Sub
End Class

Form1 code:
VB.NET:
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        frmMain.Controls.SetChildIndex(frmMain.f2, 0)
    End Sub
End Class

Form2 code:
VB.NET:
Public Class Form2
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        frmMain.Controls.SetChildIndex(frmMain.f3, 0)
    End Sub
End Class
 
Other than I don't really like using default instances like

VB.NET:
frmMain.Controls.SetChildIndex(frmMain.f3, 0)

this should work. It breaks encapsulation of the parent form a bit which is why I wanted to avoid using a different custom control for each panel. It is like having a tab control where you instanciate the controls in the TabPage's particular panel instead of the main form containing the TabControl. It's still much better than the panel stack and lots easier to come up with than the alternatives.

If this is the way you choose, you could use custom controls instead of Forms though...
 
Back
Top