Dynamically add several pictureboxes to a flowlayoutpanel?
Hi. Here's what I'm aiming for. Whenever a user creates a bookmark, it creates a new text file. The name of the file is the name of the webpage- the content of the file is the URL. Now when a user logs on, I want it so it reads all of the bookmarks, and the ones that have a file on their host page called "xpedition-icon.png", it will automatically create a new picturebox in the flowlayoutpanel with "xpedition-icon.png" as its image. When you click on the picturebox it will open a new window and navigate to the URL. Now this is what I have so far:
Code:
Try
Dim bmarks As String = medirectory + "\" + Login.UsernameTextBox.Text + "\Bookmarks"
For Each file As String In My.Computer.FileSystem.GetFiles(bmarks, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
My.Computer.FileSystem.ReadAllText(file)
Dim url As New Uri(file)
Try
If url.Host = UriHostNameType.Dns Then
Dim picURL = "http://" & url.Host & "/xpedition-icon.png"
Dim request As System.Net.WebRequest = System.Net.HttpWebRequest.Create(picURL)
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim stream As System.IO.Stream = response.GetResponseStream()
Dim pic = Image.FromStream(stream)
Dim pbox As New PictureBox
pbox.BackgroundImage = pic
pbox.Image = My.Resources.glassstrip
pbox.BackgroundImageLayout = ImageLayout.Stretch
pbox.Size = New Point(64, 64)
pbox.SizeMode = PictureBoxSizeMode.StretchImage
beef.FlowLayoutPanel2.Controls.Add(pbox)
End If
Catch
End Try
Am I on the right track? How would I even attempt doing this? Any help would be appreciated. Thanks.