Reputation: 171
I'm trying to write a program which has an expandable image feed that keeps adding pictures as I go. Before I bite off that chunk I'm just trying to get test going with a custom image class which will hold a little bit of extra info on top of the picturebox
object. The issue I'm having is that my object (oSlideItem
as clsSlideItem
) which inherits the picturebox
doesn't seem to load a picture at run time. I've tried two different methods which are mentioned in help and on this forum and I can't seem to get a picture at run time. I haven't found anything that mentions my specific situation which is inheriting the picturebox
.
I tried setting the image location and size properties before loading the picture, didn't change anything.
Are there some extra steps I need to do in order to initiate the picturebox image since I am using the functionality in an inherited state instead of a native picturebox object ?
I am also putting these image holding objects into a collection as you can see. I tested loading a picture without putting it into a collection and nothing changed so I don't think that is the issue. I am Assuming that once I add an object to a collection that the object inside the collection and the object outside the collection are decoupled. I didn't do a good test for that yet.
Public Class clsSliders
Private clFeedItems As New Collection 'collection of all feed items
Private oFeed As New clsFeed 'feed organizer layer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'build Feed
Dim oSlideItem As clsSlideItem 'feed item layer
'make collection of slider objects
oSlideItem = New clsSlideItem
oSlideItem.setRank(1, oFeed)
oSlideItem.ImageLocation = "C:\Users\nathan\Pictures\Chicago_River_from_Lake_Street_bridge.jpg"
oSlideItem.Load()
clFeedItems.Add(oSlideItem, 1)
oSlideItem = New clsSlideItem
oSlideItem.Image = Image.FromFile("C:\Users\nathan\Pictures\ReindeerPowerLines.png")
oSlideItem.setRank(2, oFeed)
'add to collection
clFeedItems.Add(oSlideItem, 2)
oSlideItem = New clsSlideItem
oSlideItem.Image = Image.FromFile("C:\Users\nathan\Pictures\TianmenMountain.jpg")
oSlideItem.setRank(3, oFeed)
'add to collection
clFeedItems.Add(oSlideItem, 3)
End Sub
'other subs and properties
End Class
and my second class:
Public Class clsSlideItem
Inherits PictureBox
Private iFeedRank As Integer 'current rank position
Public Sub setRank(rank As Integer, oFeed As clsFeed)
If Not IsNothing(oFeed) Then
Me.Left = oFeed.Left(rank)
Me.Top = oFeed.Top(rank)
Me.Width = oFeed.Width(rank)
Me.Height = oFeed.Height(rank)
iFeedRank = rank
End If
End Sub
'other subs and properties
End Class
oFeed
as clsFeed
is basically a structure which I wrote as a class so that I can have extra functionality. It's not really in the scope of this issue since that part of the code is working. I didn't include it because I didn't want to clutter up this post.
Upvotes: 2
Views: 1352
Reputation: 15813
It looks like the pictureboxes are never being added to the form controls collection. Add this
Me.Controls.Add(oSlideItem)
after
oSlideItem = New clsSlideItem
A control won't be visible on (or contained by) the form until it is added to the Controls collection. I think the images are being read just fine, only they're not displayed on the form. You can see by setting a breakpoint after the load and looking at the properties of oSlideItem (Shift-F9).
Upvotes: 1