Change order of controls in Flow Layout Panel
Hi,
I have an Flow Layout Panel that I populate with pictures. At some point it will look like :
Pic1 Pic2 Pic3 ... Picn
Lets say I choose Pic3 and I want to move it (drag n drop - or by code ) after Pic1 so the new order would be
Pic1 Pic3 Pic2 ... Picn
I found a function sendToBack but it only puts the Pic1 last , and so on.
Does anyone has an ideea what should I use for reordering controls ?
Thank you
Re: Change order of controls in Flow Layout Panel
I figured out this one myself
flowlayoutpanel.Controls.SetChildIndex(flowlayoutpanel.Controls(i), newIndex)
But now I have another problem :
How can I select one image from flow layout panel and remember its index
Re: Change order of controls in Flow Layout Panel
on image click you could, loop through the controls, checking if the name of the sender is equal to the one from the control array, then save the index as an integer..
Re: Change order of controls in Flow Layout Panel
something like this
vb Code:
Private Sub PictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click, PictureBox2.Click, PictureBox3.Click
For index As Integer = 0 To FlowLayoutPanel1.Controls.Count - 1
If TypeOf FlowLayoutPanel1.Controls(index) Is PictureBox Then
If sender.Name = FlowLayoutPanel1.Controls(index).Name Then
MessageBox.Show(index)
End If
End If
Next
End Sub
the typeof line is actually unnecessary in this case, but i like it there :D
Re: Change order of controls in Flow Layout Panel
I did it another way and it's woking ...
Private Sub pct_Click(ByVal sender As Object, _
ByVal e As EventArgs)
Dim pict As PictureBox = sender
For i = 0 To flp.Controls.Count - 1
If flp.Controls(i).Name = pict.Name Then
ind = i
End If
Next
End Sub
But as always somethingelse got my atention ...
All the pictures from Flow Layout Panel are in fact buttons with backgroundimage set on different images ... So far so good
I want to select from these buttons 1,2,3,...10...100 by holding CTRL and clicking mouse on them ... just exactly in windows explorer ... for deletion
I have no ideea if this can be done in Flow Layout Panel or where can be done but maybe someone have an ideea
Thanks
Re: Change order of controls in Flow Layout Panel
hmmmm. its the same thing you are doing ??? :-S
if you say the pictures actually are buttons, then your code shouldn't work :-/...
if it is pictureboxes you are using you could simply change the border as you click them... or just save the indexes in an array or write in tag.
and you can set an boolean value wether the ctrl button is pressed or not. use the forms keydown and keyup events... (keypreview must be set to true)