简体   繁体   中英

What does “bring to front and bring to back” on panels c# form mean

我正在使用c#拖放面板。面板不断出现和消失。我也需要面板框功能性单词(例如“前后移动”)方面的帮助,我认为这是使我的面板混乱的原因。它们是什么意思?

The Windows Forms Designer has a concept called Z-order . When two controls overlap, the Z-order determines which control will show up on top.

For example, suppose you have two controls called textBox1 and pictureBox1 on a Windows Form. Programatically, this refers to the Windows Form itself, Controls is the default list of controls in that Form, and textBox1 and is the actual control we are changing.

Selecting the menu option Bring to Front is equivalent to calling the control's BringToFront() method. This moves the control to the beginning of the default Controls collection of the Windows Form. So if you call Bring To Front on textBox1 , it will show up above all other controls on your Form. Programatically,

// Bring the control in front of all other controls
this.textBox1.BringToFront();

Selecting the menu option Send to Back is equivalent to calling the control's SendToBack() method. This moves the control to the end of the default Controls collection of the Windows Form. So if you call Send To Back on textBox1 , it will show up behind all other controls on your Form. Programatically,

// Send the control behind all other controls
this.textBox1.SendToBack();

You can also have finer control over the ordering programmatically. There is no way to do this in the UI. So:

// Put the control at the 2nd index in the Controls collection of this Form
this.Controls.SetChildIndex(this.textBox1, 2); 

This page Layering Objects on Windows Forms gives some more details.

The page Windows Forms Controls: Z-order and Copying Collections has examples on how to control Z-order programmatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM