Resolved Picturebox Slideshow

icarus26

New member
Joined
Mar 16, 2023
Messages
3
Programming Experience
Beginner
Hello,

I'm very new to VB and I'm trying to create a simple Windows APP that works something like this: it starts with a combobox and whenever an item is chosen, a correspondent listbox will appear, whenever an item is chosen in that listbox1, will appear a listbox2 (it is invisible until both combobox and previous listbox have chosen items) a correspondent listbox, and a third after that following the same rule. After the 3rd listbox has an item selected, it appears a richtextbox, also dependant on previous results, and a picturebox.
The app is a guideline to help solve problems, starting with what kind of home appliance is selected in the combobox, until the final solution is given in the richtextbox with helping pics in the picturebox Tthe picturebox has a button to next and previous pic, so no timer is needed)

My issue here has to do with the picturebox, I want for it to be invisible until all the previous lists are selected, like the previous listboxes, and to have a different slideshow of some images depending on what was selected on the third listbox.

Can some kind soul help me achieve this final part of my puzzle? It's the only thing that I could not understand how to do or find any solution...

Thank you very much in advance.
 
I have moved this thread to the Windows Forms forum. Please ALWAYS post in the most specific forum for the subject of the thread. General forums should only be used if no other forum is appropriate.
 
The visibility part should be easy, because it would work the same way as all the other controls whose visibility is changing. I'll provide one example that you should be able to adapt for all the similar cases you have:
VB.NET:
Private Sub ListBox1Changed(sender As Object, e As EventArgs) Handles ListBox1.VisibleChanged,
                                                                      ListBox1.SelectedIndexChanged
    ListBox2.Visible = ListBox1.Visible AndAlso ListBox1.SelectedItem IsNot Nothing
End Sub
You can use one method to handle both the relevant events of the parent control and then set the visibility of the child control based on both the visibility and selection of the parent control. If you were to chain this behaviour, you could unselect an item in the first ListBox and that would hide the second ListBox, which would hide the third ListBox and so on. You might also want to clear the selection in a child when you hide it:
VB.NET:
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
    ListBox1Changed()
End Sub

Private Sub ListBox1_VisibleChanged(sender As Object, e As EventArgs) Handles ListBox1.VisibleChanged
    ListBox1Changed()

    If Not ListBox1.Visible Then
        ListBox1.SelectedItem = Nothing
    End If
End Sub

Private Sub ListBox1Changed()
    ListBox2.Visible = ListBox1.Visible AndAlso ListBox1.SelectedItem IsNot Nothing
End Sub
In this case, you do use separate event handlers, because the functionality is slightly different in each case, but the common part goes in a dedicated method.
 
As for the slideshow, you can just use a field to store the current list of images and then code against that list. You can then just change the list based on other factors but the slideshow code would be exactly the same regardless. That would mean that the code above would be adapted so that, when the parent ListBox state changed, you'd set the image list appropriate first, then display the PictureBox, then probably start a Timer to change the displayed Image at intervals. The actual slideshow code would be relatively simple, e.g.
VB.NET:
Private imageIndex As Integer
Private images As Image()

Private Sub PictureBox1_VisibleChanged(sender As Object, e As EventArgs) Handles PictureBox1.VisibleChanged
    Timer1.Enabled = PictureBox1.Visible
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    imageIndex += 1

    If imageIndex >= images.Length Then
        imageIndex = 0
    End If

    PictureBox1.Image = images(imageIndex)
End Sub
 
Thanks for the fast reply jmcilhinney,

What i need is that the selection of images in the slideshow changes depending of the selected item in the previous listbox. I understand how it cn be done to a single image, but i don't know how to do that to a selection of images each time a different item in the listbox is changed. Everytime a different item is selected, the richtextbox gives a different answer and the picturebox should have a selection of different images that can be viewd through the use of two buttons, a previous image button and a next image button.
Here's some code I have:

VB.NET:
'this is the beggining of the app'
Public Class Form1
    ReadOnly problemaHeader As New Label()
    ReadOnly categoriaHeader As New Label()
    ReadOnly causaHeader As New Label()

    Dim images(2) As Bitmap
    Dim pos As Integer = 0

    Private imagensPorOpcao As New Dictionary(Of String, Image()) From {
    {"Desinstale/Instale a aplicação ou atualize para a versão mais recente", {My.Resources.registo1, My.Resources.registo2}}}

    Public Sub New()
        InitializeComponent()
        Me.DoubleBuffered = True

    End Sub

    Private Sub APPLIANCE_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        categoriaHeader.Visible = False
        Me.Controls.Add(categoriaHeader)
        problemaHeader.Visible = False
        Me.Controls.Add(problemaHeader)
        causaHeader.Visible = False
        Me.Controls.Add(causaHeader)

        DESCRICAO.BackColor = Color.White

        PICS.Image = images(pos)

        images(0) = CA.My.Resources.registo1
        images(1) = CA.My.Resources.registo2


        APPLIANCE.Items.Clear()
        CATEGORIA.Items.Clear()
        PROBLEMA.Items.Clear()
        APPLIANCE.Items.AddRange({"Máquina de Lavar Roupa", "Máquina de Secar Roupa", "Máquina de Lavar Louça", "Frio", "Placa", "Forno", "Microondas", "Exaustor", "Hoover Jazmine HF9"})
    End Sub
    Private Sub BTN_PREVIOUS_Click(sender As Object, e As EventArgs) Handles BTN_PREVIOUS.Click

        pos = pos - 1
        If pos >= 0 Then
            PICS.Image = images(pos)
        Else
            pos = 0
        End If
    End Sub
    Private Sub BTN_NEXT_Click(sender As Object, e As EventArgs) Handles BTN_NEXT.Click

        pos = pos + 1

        If pos < images.Length - 1 Then

            PICS.Image = images(pos)

        Else pos = images.Length

        End If
    End Sub


    Private Sub CATEGORIA_SelectedIndexChanged(sender As Object, e As EventArgs) Handles APPLIANCE.SelectedIndexChanged

        If APPLIANCE.SelectedIndex <> -1 Then
            categoriaHeader.Location = New Point(CATEGORIA.Location.X, CATEGORIA.Location.Y - categoriaHeader.Height - 1)
            categoriaHeader.Visible = True
            categoriaHeader.Font = New Font(categoriaHeader.Font.FontFamily, 12, FontStyle.Bold)
            categoriaHeader.Text = "Selecione a categoria"
            categoriaHeader.AutoSize = True
            categoriaHeader.BackColor = Color.FromArgb(0, 91, 170)
            categoriaHeader.ForeColor = Color.White
        Else
            problemaHeader.Visible = False
        End If

        CATEGORIA.Items.Clear()
        PROBLEMA.Items.Clear()


        If APPLIANCE.SelectedItem = "Máquina de Lavar Roupa" Then
            CATEGORIA.Items.AddRange({"Conectividade", "Display", "Erros", "Entrada e saída de água", "Fuga de água", "Programação e funcionamento", "Gaveta de detergente", "Lavagem e Tempos", "Porta", "Tambor", "Ruído"})
        ElseIf APPLIANCE.SelectedItem = "Máquina de Secar Roupa" Then
            CATEGORIA.Items.AddRange({"Conectividade", "Erros", "Porta", "Programação e funcionamento", "Secagem", "Tempo"})
        ElseIf APPLIANCE.SelectedItem = "Máquina de Lavar Louça" Then
       
        'it goes on until'
       
               If APPLIANCE.SelectedItem = "" Then
            CATEGORIA.Visible = False
        Else
            CATEGORIA.Visible = True
        End If

    End Sub
   
    'the next one'
    Private Sub PROBLEMA_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CATEGORIA.SelectedIndexChanged, APPLIANCE.SelectedIndexChanged

        If CATEGORIA.SelectedIndex <> -1 Then
            problemaHeader.Location = New Point(PROBLEMA.Location.X, PROBLEMA.Location.Y - problemaHeader.Height - 1)
            problemaHeader.Visible = True
            problemaHeader.Font = New Font(problemaHeader.Font.FontFamily, 12, FontStyle.Bold)
            problemaHeader.Text = "Selecione a anomalia"
            problemaHeader.AutoSize = True
            problemaHeader.BackColor = Color.FromArgb(0, 91, 170)
            problemaHeader.ForeColor = Color.White

        Else
            problemaHeader.Visible = False
        End If


        PROBLEMA.Items.Clear()
        If APPLIANCE.SelectedItem = "Máquina de Lavar Roupa" And CATEGORIA.SelectedItem = "Conectividade" Then
            PROBLEMA.Items.AddRange({"Usuário não consegue registar o equipamento na APP", "Nº de série não aceite", "Nº de série já em uso / Usuário quer alterar email", "Wi-Fi não conecta", "Bluetooth não conecta", "Máquina de Lavar Roupa apresenta Offline"})
        ElseIf APPLIANCE.SelectedItem = "Máquina de Lavar Roupa" And CATEGORIA.SelectedItem = "Display" Then
            PROBLEMA.Items.AddRange({"Os botões não aceitam os comandos", "O visor não liga", "O visor altera a informação por si só", "A máquina não inicia"})
           
            'closing the same way'
           
              If CATEGORIA.SelectedItem = "" Then
            PROBLEMA.Visible = False
        Else
            PROBLEMA.Visible = True
        End If
    End Sub
   
'next one'

Private Sub CAUSA_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles PROBLEMA.SelectedIndexChanged, CATEGORIA.SelectedIndexChanged, APPLIANCE.SelectedIndexChanged

        CAUSA.Items.Clear()
        If APPLIANCE.SelectedItem = "Máquina de Lavar Roupa" And CATEGORIA.SelectedItem = "Conectividade" And PROBLEMA.SelectedItem = "Usuário não consegue registar o equipamento na APP" Then
            CAUSA.Items.AddRange({"Desinstale/Instale a aplicação ou atualize para a versão mais recente", "Limpe a cache da aplicação nas configurações do telemóvel"})
        ElseIf APPLIANCE.SelectedItem = "Máquina de Lavar Roupa" And CATEGORIA.SelectedItem = "Conectividade" And PROBLEMA.SelectedItem = "Nº de série não aceite" Then
            CAUSA.Items.AddRange({"Verifique se o equipamento tem funcionalidade de conectividade", "Verifique se usuário está a escolher o tipo de equipamento correto", "Verifique se o usuário está a usar a aplicação correta", "Verifique se o código QR está a ser lido corretamente"})
        ElseIf APPLIANCE.SelectedItem = "Máquina de Lavar Roupa" And CATEGORIA.SelectedItem = "Conectividade" And PROBLEMA.SelectedItem = "Nº de série já em uso / Usuário quer alterar email" Then
            CAUSA.Items.AddRange({"Solicite a remoção do nº de série"})
           
            'ending as'
               If PROBLEMA.SelectedItem = "" Then
            CAUSA.Visible = False
        Else
            CAUSA.Visible = True
        End If
    End Sub
   
    'next one'
   
      Private Sub DESCRICAO_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles CAUSA.SelectedIndexChanged, PROBLEMA.SelectedIndexChanged, CATEGORIA.SelectedIndexChanged, APPLIANCE.SelectedIndexChanged


        If PROBLEMA.SelectedIndex <> -1 Then
            causaHeader.Location = New Point(CAUSA.Location.X, CAUSA.Location.Y - causaHeader.Height - 1)
            causaHeader.Visible = True
            causaHeader.Font = New Font(causaHeader.Font.FontFamily, 12, FontStyle.Bold)
            causaHeader.Text = "Selecione a solução"
            causaHeader.AutoSize = True
            causaHeader.BackColor = Color.FromArgb(0, 91, 170)
            causaHeader.ForeColor = Color.White
        Else
            causaHeader.Visible = False
        End If

        DESCRICAO.ReadOnly = True

        If APPLIANCE.SelectedItem = "Máquina de Lavar Roupa" And CATEGORIA.SelectedItem = "Conectividade" And PROBLEMA.SelectedItem = "Usuário não consegue registar o equipamento na APP" And CAUSA.SelectedItem = "Desinstale/Instale a aplicação ou atualize para a versão mais recente" Then
            DESCRICAO.Visible = True
            DESCRICAO.Text = "Para conectar seu dispositivo móvel à aplicação, considere os seguintes aspectos:
           
            'ending with'
               Else
            DESCRICAO.Visible = False
        End If

So, my next step is just ending all the richtextbox descriptions and assigning a different slideshow of pictures to each selected item in the listbox "CAUSA".

Can you please help me with that?

This is the look of the app:
Sem título.png


Thank you very much
 
Last edited:
Why can't you have an array of Image arrays and then you use the SelectedIndex of the ListBox to get the corresponding array? You then assign that to the field in my previous code and do exactly what I said.
 
Hello jmcilhinney,

Thank you so much for this. Following your tips I achieved what I wanted to do, adding this code:

VB.NET:
  Dim imageArrays()() As Image = New Image(2)() {}
    Private currentImageIndex As Integer = 0
    Private selectedArrayIndex As Integer
    
         imageArrays(0) = New Image() {My.Resources.registo1, My.Resources.registo2}
        imageArrays(1) = New Image() {My.Resources.registo2, My.Resources.registo1}
        imageArrays(2) = New Image() {My.Resources.teste1, My.Resources.teste2}
        
        Private Sub BTN_PREVIOUS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_PREVIOUS.Click
        currentImageIndex -= 1
        If currentImageIndex < 0 Then
            currentImageIndex = imageArrays(selectedArrayIndex).Length - 1
        End If
        PICS.Image = imageArrays(selectedArrayIndex)(currentImageIndex)
    End Sub

    Private Sub BTN_NEXT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_NEXT.Click
        currentImageIndex += 1
        If currentImageIndex >= imageArrays(selectedArrayIndex).Length Then
            currentImageIndex = 0
        End If
        PICS.Image = imageArrays(selectedArrayIndex)(currentImageIndex)
    End Sub
    
        Private Sub PICS_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CAUSA.SelectedIndexChanged, PROBLEMA.SelectedIndexChanged, CATEGORIA.SelectedIndexChanged, APPLIANCE.SelectedIndexChanged
        If APPLIANCE.SelectedItem = "Máquina de Lavar Roupa" And CATEGORIA.SelectedItem = "Conectividade" And PROBLEMA.SelectedItem = "utilizador não consegue registar o equipamento na APP" And CAUSA.SelectedItem = "Desinstale/Instale a aplicação ou atualize para a versão mais recente" Then
            PICS.Visible = True
            BTN_NEXT.Visible = True
            BTN_PREVIOUS.Visible = True
            selectedArrayIndex = CAUSA.SelectedIndex
            PICS.Image = imageArrays(selectedArrayIndex)(0)
        ElseIf APPLIANCE.SelectedItem = "Máquina de Lavar Roupa" And CATEGORIA.SelectedItem = "Conectividade" And PROBLEMA.SelectedItem = "utilizador não consegue registar o equipamento na APP" And CAUSA.SelectedItem = "Limpe a cache da aplicação nas configurações do telemóvel" Then
            PICS.Visible = True
            BTN_NEXT.Visible = True
            BTN_PREVIOUS.Visible = True
            selectedArrayIndex = (1)
            PICS.Image = imageArrays(selectedArrayIndex)(0)
        ElseIf APPLIANCE.SelectedItem = "Máquina de Lavar Roupa" And CATEGORIA.SelectedItem = "Conectividade" And PROBLEMA.SelectedItem = "Nº de série não aceite" And CAUSA.SelectedItem = "Verifique se utilizador está a escolher o tipo de equipamento correto" Then
            PICS.Visible = True
            BTN_NEXT.Visible = True
            BTN_PREVIOUS.Visible = True
            selectedArrayIndex = (2)
            PICS.Image = imageArrays(selectedArrayIndex)(0)



        Else
            PICS.Visible = False
            BTN_NEXT.Visible = False
            BTN_PREVIOUS.Visible = False

        End If
    End Sub

It works like a charm! Thank you again for your precious help!!!
 
Back
Top