问题
What is the difference between Show/Hide and BringToFront/SendToBack? In which situation we should use one pair instead of the other?
回答1:
These are completly different methods.
Show()
: shows the control on the view, by initializing the content of it before.
BringToFront
and SendToBack
act on Z-order
of that control in regard of others.
But the control is already visible.
Hints from MSDN on BringToFront:
Brings the control to the front of the z-order.
and on Show:
Displays the control to the user.
回答2:
Show()
is equivalent for setting Visible = true
. It does not change control's Z-order. If control is closed by some other control, which is in front of Z-order, user still will not be able to see your control.
BringToFront()
changes control's Z-order (brings to front), but does not change it's visibility. If control is hidden, then it will remain hidden. But when you make your control visible, it will appear at the front of all other controls.
Same with Hide()
(makes control invisible, but does not change Z-order) and SendToBack
(does not change visibility, but brings control to back).
回答3:
Show/Hide will show or hide the control on screen. Basically it makes it visible or not.
BringToFront/SendToBack will change its "z" order. If you have a button under a label and you call "BringToFront" on the button, the button will now hide the label.
回答4:
BringToFront simply moves a control in front of other controls (In other words, it will cover up another control) and SendToBack will allow other controls to cover it up whereas Show / Hide will actually fully show / fully hide the control from the user.
As a general rule, you want to Show / Hide controls
来源:https://stackoverflow.com/questions/13058043/what-is-the-difference-between-control-show-and-bringtofront