Results 1 to 6 of 6

Thread: Change order of controls in Flow Layout Panel

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    58

    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

  2. #2

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    58

    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

  3. #3
    Hyperactive Member gnaver's Avatar
    Join Date
    Jul 2005
    Location
    Denmark/Sweden
    Posts
    289

    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..

  4. #4
    Hyperactive Member gnaver's Avatar
    Join Date
    Jul 2005
    Location
    Denmark/Sweden
    Posts
    289

    Re: Change order of controls in Flow Layout Panel

    something like this

    vb Code:
    1. Private Sub PictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click, PictureBox2.Click, PictureBox3.Click
    2.         For index As Integer = 0 To FlowLayoutPanel1.Controls.Count - 1
    3.             If TypeOf FlowLayoutPanel1.Controls(index) Is PictureBox Then
    4.                 If sender.Name = FlowLayoutPanel1.Controls(index).Name Then
    5.                     MessageBox.Show(index)
    6.                 End If
    7.             End If
    8.         Next
    9.     End Sub

    the typeof line is actually unnecessary in this case, but i like it there

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    58

    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

  6. #6
    Hyperactive Member gnaver's Avatar
    Join Date
    Jul 2005
    Location
    Denmark/Sweden
    Posts
    289

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width