Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
623 views
in Technique[技术] by (71.8m points)

c# - WinForm UI components layer order

When we add any UI or container in WinForms, the later added component comes over the earlier added components, we can say it is in a higher layer.

How to change that layer order or component order after adding components?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When you place more than one control in the same place,one will end up on top,and the other will end up underneath.Usually this is the result of a minor mistake,such as incorrectly using the anchoring and docking features to creare resizable form.In some cases,however,you might want to overlap control for a specific effect.

When control overlap,it's the z-index that determines which control ends up on top.Essentially,every control existy in its own distinct numbered layer.A control that has the z-index layer 1 will appear above a control in z-index layer 2 if they overlap.Usually,the z-index of a group of controls is determined by the order in which you add the controls,so that the last control you add is always in the topmost layer (with a z-index of 0).

However, you can change these options.

To determine or set the z-index of a control , you can use the GetChildIndex() and SetChildIndex() methods of the Controls Collection.Here's an example that moves a control to the third layer in the z-index.

Controls.SetChildIndex(ctrl, 2);

Usually, you won't need this kind of find-grained control.Instead,you'll just want to drop a control to the back of the z-index (the bottom-most layer) or bring it to the top.You can accomplish this feature at design time by right clicking on a control and choosing Bring to Fron or Send to Back.You can also perform the same task programmatically using the Control.BringToFront() or Control.SendToBack() methods.

ctrl.BringToFront(); // This is equivalent to Controls.SetChildIndex(ctrl,0);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...