Question

first post here. I have a relatively bad question - but I'm new to this so bear with me.

I'm writing a simple app for a friend to track some daily problems/behaviors for reporting purposes. I was trying to use almost a wizard style, but the wizard examples I found were either needlessly complex or antiquated.

What I have is a Windows form with - for arguments sake - 5 panels, stacked on top of each other. Each panel contains a different set of controls (I wasn't able to completely re-use all of them or go in a 'template' direction). Below the panels are 3 buttons - Cancel, Back, Next.

All I want to be able to do is navigate between the panels with the Next and Back buttons. i.e. When I click 'Next', the click event sets the variable values from panel A, and then hides it and loads panel B, then Next sets the values for B and loads C and so on.

I thought I could do this with some sort of array or list of objects, but I'm not really sure the best way to go about it. I asked in another forum, and the only answer I got was to add the buttons to the panel and have them be specific to bringing forms front and back. That seems awfully inefficient and I know there's a better way to do it. Can you guys shed some light on this?

Was it helpful?

Solution

I personally would create a List<Of Panel> and add the Panels to it. Then use a integer and increment it between 0 to 4, using BringToFront to show the Current Panel. Something like this.

Public Class Form1
    Dim myPanels As List(Of Panel) = New List(Of Panel)
    Dim count As Integer = 0

    Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
        count = 0
        myPanels(count).BringToFront()
    End Sub

    Private Sub btnNext_Click(sender As System.Object, e As System.EventArgs) Handles btnNext.Click
        If count < 4 Then
            count += 1
        Else
            count = 0
        End If
        myPanels(count).BringToFront()
    End Sub

    Private Sub bntPrevious_Click(sender As System.Object, e As System.EventArgs) Handles btnPrevious.Click
        If count > 0 Then
            count -= 1
        Else
            count = 4
        End If
        myPanels(count).BringToFront()
    End Sub

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        myPanels.Add(Panel1)
        myPanels.Add(Panel2)
        myPanels.Add(Panel3)
        myPanels.Add(Panel4)
        myPanels.Add(Panel5)
        myPanels(count).BringToFront()

    End Sub
End Class
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top