In CSS, we have a Property called z-index, what is the same in WinForms set for a Panel control to the "Z-Index?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
WinForms has a z-order, but you can’t access it as a number. Instead, every control has a
BringToFrontmethod and aSendToBackmethod, which move the control to the top of the z-order or to the bottom, respectively.Not sure exactly why it was exposed this way, although you rarely encounter situations where either BringToFront or SendToBack don’t provide what you need.
Update: I’m wrong, you can access the z-order directly via a method on the control’s container’s
Controlscollection. Here’s a simple method that wraps it:I’m guessing they encapsulated this in
BringToFrontandSendToBackjust to keep everything simple and easy to use. I applaud.Update 2: I interpreted your comments to a different answer here to mean that you want to be able to take a control that is inside a panel and larger than the panel (so that part of it is hidden) and make it so that the control is in front of the panel and larger than it (so that you see the whole control).
You can do this by removing the control from the panel, shifting its position by the original panel’s position, and adding it to the form’s controls:
The Left and Top shifts are necessary because the button’s position was originally relative to the panel, and will now be relative to the form. The shifts keep it in the original virtual position, so it appears to come out of the panel.
You would then have to deal with putting it back in the panel, which is just a reverse of the above code.