Bring Winforms control to front

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

    I think you just need to change your last line:

    userContainer.Controls[field.FieldName].BringToFront(); 
    

    to this:

    userContainer.Controls[field.Name].BringToFront(); 
    

    When you use a string as the indexer for the Controls collection, it goes by the Name property of the control (not the FieldName property).

    Since you're just trying to bring the most recently-added control to the top, this would also work:

    userContainer.Controls[userContainer.Controls.Count - 1].BringToFront();
    

提交回复
热议问题