help with VB 2008

Associate
Joined
31 Jul 2008
Posts
1,328
Location
London
I am trying to get a panel to display 5 item from a arraylist using the graphics tool but i can only get it to display every item in the arraylist.
So if is 10 items in the arraylist the panel will show the first 5 items and if i click on the next button the panel will show items 2 - 6.

here is the code for the panel:

Code:
Private Sub pnlDisplay_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pnlDisplay.Paint
        Dim strOutput As String
        Dim x, y As Integer
        x = 5
        y = 5
        Dim fntOut As New Font("Time New Roman", 10.0F)
        Dim currBrush As New SolidBrush(Color.Black)
        Dim i As Integer
        While i < nCurrentTask
            g.FillEllipse(colour, x, y, 15, 15)
            currTask = arrList(i)
            strOutput = currTask.GetDescription + " " + currTask.GetTaskDate
            g.DrawString(strOutput, fntOut, currBrush, x + 20, y)
            y += Convert.ToInt32(fntOut.Height)
            i += 1
            GrabInfo()
        End While
    End Sub

here is the code for the navigation button:

Code:
rivate Sub NextTask()

        If nCurrentTask < arrList.Count Then
            nCurrentTask += 1
        Else
            nCurrentTask = arrList.Count
        End If
        pnlDisplay.Invalidate()
        labelDisplay()

    End Sub

any help will be appricated

Tony
 
Last edited:
Why are you painting text to a panel if you want it uneditable use a label and turn autosize off or a listbox and prevent editting, painting it just seems messy.

Basically you need to only get the first 5 items then the next 5 so you need to just use an if statement in your while to only get the values from the array you need and ignore any that don't fall in your range. So when they click next you need to know where you are in the array so you can move your range accordingly.
 
Why are you painting text to a panel if you want it uneditable use a label and turn autosize off or a listbox and prevent editting, painting it just seems messy.

Part of an excise I have got

Basically you need to only get the first 5 items then the next 5 so you need to just use an if statement in your while to only get the values from the array you need and ignore any that don't fall in your range. So when they click next you need to know where you are in the array so you can move your range accordingly.

I appricate you help but is there any chance you can simplify that if that even possible :confused:

sorry for the silly questions I am new at this
 
What Tubbz is saying is you should put an if statement in the while loop that only prints out the numbers if the index into the array falls within a range. So wrap the contents of your while loop into an if statement. The condition will be something like:

Code:
if(i >= (nCurrentTask-5)) && (i < nCurrentTask))

Something like that anyway, I'm pretty tired so it might not be completely correct but it will do to give you an idea of what you need :)
 
vb console app that sort of shows how :) just start a new console app and paste it in. use s to go down the list and w to go up it...

Code:
Module Module1
    Dim pos As Integer = 0 'stores the last position e.g.
    Dim array(100) As Integer

    Sub Main()
        For i As Integer = 0 To 99 ' fill the array with 100 different values
            array(i) = i * 100
        Next

        While True
            Dim key As ConsoleKeyInfo = Console.ReadKey()
            If key.KeyChar = ChrW(100) Then ' key press D to up the list
                If (pos + 5) <= 99 Then 'if its greater than the elements in the array don't increase the count
                    pos += 5
                End If

                display() 'print the values

            ElseIf key.KeyChar = ChrW(97) Then 'key press a to go down the list

                If (pos - 5) >= 0 Then 'f its 0 don't reduce the count
                    pos -= 5
                End If

                display()
            End If
        End While
    End Sub

    Sub display()
        For i As Integer = 0 To 99
            If i >= pos And i < (pos + 5) Then 'only show the values in the range of pos to pos + 5
                Console.WriteLine("* " & array(i))
            End If
        Next
        Console.WriteLine(vbNewLine & "*********************")
    End Sub
End Module
 
Back
Top Bottom