0

Load a picture box with an image. Then, load an overlapping picture box and its image goes on top nicely. But, when I load a third picture box, it goes in between the first and the second. What determines priorities and how can I overlap several picture boxes with the last being on top? thanks, hope this is not trivial, Bill

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by GeekByChoiCe
0

The "SetChildIndex" is the key.
Check out this example:

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
		'create panel
		Dim imagePanel As New Panel With {.Width = 500, .Height = 500}
		Me.Controls.Add(imagePanel)
		'create images
		Dim pictures() As String = IO.Directory.GetFiles("C:\Users\Public\Pictures\Sample Pictures")
		Dim x As Integer = 1
		For Each pic In pictures
			Dim img As New PictureBox With {.Height = 100, .Width = 100, .Location = New Point(40 * x, 40 * x), .ImageLocation = pic, .Name = "pic" & x}
			AddHandler img.MouseHover, AddressOf Image_MouseHover
			imagePanel.Controls.Add(img)
			imagePanel.Controls.SetChildIndex(img, imagePanel.Controls.Count - x)
			x += 1
		Next
	End Sub

	Private Sub Image_MouseHover(sender As Object, e As EventArgs)
		Debug.WriteLine(CType(sender, PictureBox).Name)
	End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.