Bring Winforms control to front

前端 未结 5 699
刺人心
刺人心 2020-12-03 21:05

Are there any other methods of bringing a control to the front other than control.BringToFront()?

I have series of labels on a user control and when I

5条回答
  •  伪装坚强ぢ
    2020-12-03 21:40

    From my experience looks like windows puts all controls belonging to one graphic container(pane, group box...etc) in a software collection. The collection is ordered by child index which is a property of every control in that container. The trick is that children with the same index can and do exists. In this case windows will paint those children ordered relative to others but between them it will paint them in the reverse order they had been added to the container.

    Long story short: for one container-you need to make sure controls have different indexes by changing ALL NOT just SOME of the indexes when you want to change the z-order. For example:

    foreach (Control newControl in TopControl.Controls)
    {
       TopControl.Controls.SetChildIndex(newControl,indexlogic(newControl));
    }
    

    where indexLogic(newControl ) is your method of calculation of the index of particular control.

提交回复
热议问题