How to get controls from panel in specific order in winforms

  • Thread starter Thread starter qauaan
  • Start date Start date
Q

qauaan

Guest
I put different picturebox in panel in order (a horizental line). on runtime i add some more pictureboxes in panel anywhere in previous line of pictureboxes.
Now i want to get piture boxes in particular order as they are appear in the form. if i use loop like


foreach
(PictureBox p in
panel.Controls)
{
//here is my code<br/>

}

it gives the controls in order as we insert them into picture box. e.g if my panel has three picture boxes like

picbox1 picbox2 picbox3

it give the first picturebox1 then 2 and so on. The problem is one that when we insert new picturebox between picbox1 and picbox2. now the panel is like
picbox1 picbox4 picbox2 picbox3
Now want to access the controls in such order that first picbox1,then picbox4 and then picbox2 and picbox3 . (how can we access them plz give me some idea.) if i use the previous code its now also give me the controls in order like picbox1,2,3 and so on as we add these controls in panel. I also try like this


PictureBox p = (PictureBox)panel1.GetNextControl(selectedPicBox, true
);


but it also give the order in-which we insert the controls in the panel . I think that these order become the index the panel. if there is any way that we change the index of any control within the panel or we insert the new control in previous index of panel. (Such as we can do in List like List.insert(2,value);) I use the winforms.

Continue reading...
 
Back
Top