0

I create the picture box into an object and a container holds all the objects. So, I call the returnIcon method which uses generateIcon if necessary. I have a method in the container to search for the correct object and then returns the icon for that object. A form creates the container. It is there I call for icons and then send them to a user control where it is to be displayed. My problem is that the picture box only displays the last time it is called. I know each object is being found correctly. In the user control, I used picturebox.name and each one was correct. The value is being sent, but the image is not displaying. Why will only the last picture box call display?

base object is the basic LeagueObject where it contains the picturebox that is created when needed (depends on the boolean iamset).

the container is basically only a list of the LeagueObjects (it is set up this way for JSON deserialization).

The picture box travels: League(base)object >> container >> form >> userControl that is loaded into the form (there are ten user controls added to the form) The only picture boxes that show are the last user controls that need the pictureBox.

- base object

        Protected Sub generateIcon()
            If Not iamset Then
                img.Width = 45
                img.Height = 45
                img.SizeMode = PictureBoxSizeMode.Zoom
                img.BorderStyle = BorderStyle.None
                Try
                    img.Image = System.Drawing.Image.FromFile(Path.Combine(Path.GetTempPath(), "lolIcons", type, image.full))
                Catch ex As Exception
                End Try
                img.BackColor = Color.White
                setIcon()
                AddHandler img.Click, AddressOf onIconClick
                iamset = True
            End If
        End Sub
            Public Function returnIcon() As PictureBox
                generateIcon()
                Return img
            End Function

    - base object collection    


      Public Function returnImageById(ByVal strID As String) As PictureBox
                For Each champ In league_container.data
                    If champ.Value.id.ToString = strID Then
                        Console.WriteLine("found " + champ.Value.name)
                        Return champ.Value.returnIcon()
                    End If
                Next
                Console.WriteLine("Failed to find " + strID)
                Return New PictureBox
            End Function

- form

    Public Sub loadUC(ByVal player As LeagueCurrentGameParticipant, ByVal kills As Double, ByVal deaths As Double, ByVal assists As Double, ByVal largestKillingSpree As Double, ByVal largestMultiKill As Double, ByVal killingSprees As Double, ByVal doubleKills As Double, ByVal tripleKills As Double, ByVal quadraKills As Double, ByVal pentaKills As Double, ByVal unRealKills As Double)
            Dim uc As New ucMatchSummoner
            uc.loadUC(player, rgocm.returnImageById(player.championId.ToString), rgossm.returnImageById(player.spell1Id.ToString()), rgossm.returnImageById(player.spell2Id.ToString()), kills, deaths, assists, largestKillingSpree, largestMultiKill, killingSprees, doubleKills, tripleKills, quadraKills, pentaKills, unRealKills)
            tblpMain.Controls.Add(uc)
        End Sub

- user control (This one is actually longer but I truncated it since it served no purpose. I was sending it ByVal but attempted ByRef in case anything changed, which it did not.

      Public Sub loadUC(ByRef lcgp As LeagueCurrentGameParticipant, ByVal champImage As PictureBox, ByRef spell1 As PictureBox, ByRef spell2 As PictureBox, ByVal kills As Double, ByVal deaths As Double, ByVal assists As Double, ByVal largestKillingSpree As Double, ByVal largestMultiKill As Double, ByVal killingSprees As Double, ByVal doubleKills As Double, ByVal tripleKills As Double, ByVal quadraKills As Double, ByVal pentaKills As Double, ByVal unRealKills As Double)
            lp = lcgp
            loadPlayerCurrentGameInformation()
            pnlChampIcon.Controls.Add(champImage)
            flpSpells.Controls.Add(spell1)
            flpSpells.Controls.Add(spell2)
    End class
  • You might want to spend some time explaining better. Terms like object, base object, *base object collection* and *a container holds all the objects* make it vague and hard to follow. Does "container" mean `UserControl`? It halfway looks like you are (re)creating a picturebox inside a usercontrol? Why? You dont need to recreate a control in order to display a different image. – Ňɏssa Pøngjǣrdenlarp Nov 29 '17 at 04:27
  • LeagueObject is just a basic object with some information. The container is a list of LeagueObjects with some additional information. You could look at it as a list of objects with a picture box property for each object. I only used controls.add(PictureBox), I did not think I was recreating anything. I did not want to post all the code for the objects since it is a lot. – Ralph Maurmeier Nov 29 '17 at 04:36
  • I also edited the question in an attempt to clarify my question. – Ralph Maurmeier Nov 29 '17 at 04:41
  • That `iamset = True` flag should prevent any but the *first* image from showing if you are assigning new class items to an existing UserControl . Implementing a PictureBox in a class object rather than the userControl seems extremely odd. PBs are a user view thing not a code/class type thing. – Ňɏssa Pøngjǣrdenlarp Nov 29 '17 at 05:41
  • All the information on how to build the picture box is in one location, it made it easier instead of having to instantiate manually on a form. The collection is created using a json string which has the file path inside of it. I guess I could find another way to instantiate it on the form instead of in the class. Why would the iamset flag prevent any other images from showing? I figured if I was returning a created image, it would be able to return it again. – Ralph Maurmeier Nov 29 '17 at 05:44

1 Answers1

0

Apparently, Picture boxes are not able to be returned over and over again like a string. So, I can quickly create the image multiple times. The main reason for the flag was because I was downloading the image each time, now I just keep a collection of images in a temp folder and access the images there, which works efficiently. The flag iAmSet would prevent the picture box from being created multiple times, so I removed the flag and all works as expected.

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
  • No, the problem was that the image assignment was inside the `If iamset ` check. Some of the stuff might only need to be set once for a PB like the location, but not the image if you want it to change. If course using a Picture Box as a data storage element is suboptimal. – Ňɏssa Pøngjǣrdenlarp Nov 30 '17 at 01:43
  • I don't want the image to change though. For example, I have heal, teleport, and flash. Each has their own icon (image). I have to use those three icons multiple times for multiple players. A JSON string contains all the data for the those three spells and I have it deserialize into the objects. I guess the reason we chose this way is we only have to change one picture box to change them all. I guess we could have made a class NewPictureBox and then used the images to go to our NewPictureBox. I just liked having one class that did everything I needed. It has more code than just that. – Ralph Maurmeier Nov 30 '17 at 03:56
  • If I haven't said it enough, I want to thank you. You have been the single most helpful person on this site and I greatly appreciate all the advice you have given me. I'll be graduating soon but all this has been a separate personal project of mine. Thank you. – Ralph Maurmeier Nov 30 '17 at 03:57