Bring Winforms control to front

前端 未结 5 695
刺人心
刺人心 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:50

    Yeah, there's another way. The Controls.SetChildIndex() also changes Z-order. The one with index 0 is the one on top. Doesn't buy you anything though, BringToFront() uses this method.

    Your SendLabelsToBack() method as given cannot work, it will also send the label to added to the back. But your next statement fixes that again.

    Okay, that doesn't work, which means the BringToFront() method doesn't get executed. Look in the Output window for a "first chance exception" notification. As written, your SendLabelsToBack() will cause an exception if the user control contains any control other than a UserLabel. Also, set a breakpoint after the BringToFront() call and check the value of userContainer.Controls[0].Name when it breaks.

提交回复
热议问题