Make A Control Be On Top
Asked Answered
V

2

7

I have this one Image and I want it to be on top of another image.

(window form application, c#)

Veliavelick answered 13/1, 2011 at 19:23 Comment(1)
Is there a bring to front or bring to top method? Either in code or even a right click menu in the IDEAbutilon
I
9

If it's one control partially overlapping another, and you want one or the other on top, right-click the image you want on top in the designer, and choose "Bring To Front". There is a "Send To Back" that you can use on the image you want behind the other.

If you want partial transparency, like an alpha mask on the top image or a gradient blend between two images right on top of the other, you'll probably need the more advanced capabilities of WPF graphics. You CAN do pixel-by-pixel effects in WinForms, but there isn't anything built in to Winforms to handle image transparency, and per-pixel manipulation of an Image in Winforms won't take advantage of any graphics acceleration (100% CPU, with the runtime's overhead slowing you down further).

Intrust answered 13/1, 2011 at 20:22 Comment(0)
D
14

In the code you have a few of calls you can make. BringToFront and SendToBack are probably the simplest:

yourControl.BringToFront();
yourControl.SendToBack();

Also you could control that from the control's parent container using Control.ControlCollection.SetChildIndex. For example:

// Bring control to front    
MyForm.Controls.SetChildIndex(SomeControl, 0); 

Otherwise just click "Bring to Front" or "Send to back" in the designer, as @KeithS has already answered.

Dicho answered 27/6, 2013 at 9:17 Comment(1)
Did not work for me, I ended up using someControl.BringToFront()Intended
I
9

If it's one control partially overlapping another, and you want one or the other on top, right-click the image you want on top in the designer, and choose "Bring To Front". There is a "Send To Back" that you can use on the image you want behind the other.

If you want partial transparency, like an alpha mask on the top image or a gradient blend between two images right on top of the other, you'll probably need the more advanced capabilities of WPF graphics. You CAN do pixel-by-pixel effects in WinForms, but there isn't anything built in to Winforms to handle image transparency, and per-pixel manipulation of an Image in Winforms won't take advantage of any graphics acceleration (100% CPU, with the runtime's overhead slowing you down further).

Intrust answered 13/1, 2011 at 20:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.