sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.7k stars 638 forks source link

[Question] Using transparency with Windows forms and SharpDX #931

Open nickdesj79 opened 7 years ago

nickdesj79 commented 7 years ago

I have a pictureBox that is rendered by SharpDX deviceContext 2D1.

I want to know if this is possible to add an other small control over it and blend it with the background underneath to create a transparency effect. Using the control.BackColor = Color.Transparent seems to see it's parent control as being fully gray like if nothing had been rendered on the pictureBox. However it's not the case, I have drawn a SharpDX.Direct2D1.Bitmap on the picture Box. but the children control doesn't see it so it cannot take it's color and make a transparency effect.

kburgoyne commented 7 years ago

The only input I can provide is I've got a SwapChainPanel in the background overlaid by several nested Grid controls containing various drawn elements. Some are buttons using standard XAML SymbolIcon or FontIcon icons, some are buttons with unique icons drawn using XAML Paths, some just drawn graphics like ellipses and lines.

These all form the heads-up-display (HUD) over the top of my virtual world drawn in the SwapChainPanel. Most of these don't use transparent color fills. They use no background brush (null). However two of the ellipses are filled with transparent brush and are used as touch-screen thumbsticks when running on a phone or maybe tablet with no gamepad (XBox controller). The transparent brush is necessary in order to get the fill area of the ellipse to respond to hit testing.

They all render "see through" to the SwapChainPanel. I don't use bitmaps, so I can't say anything about those.

I can say the Win10 phone emulators don't seem to render background blending properly, but a phone (like the 950XL) doesn't have a problem. I get semi-transparent grayish boxes for some of the transparent areas on the emulators. Since the phone itself doesn't appear to have the problem, I've been ignoring the problem on the emulators. With the Win10 UWP architecture I've find very little reason to do much testing on either a phone or phone emulators. Pretty much once I've had versions working fine on my development PC, it's also "just worked" on the phone.

BEEden commented 7 years ago

I can’t speak for WPF, but this can be achieved using Windows Forms. You’ll need to override the CreateParams property (outside the scope of this discussion, there are some excellent examples on CodeProject dot com demonstrating this) and use the DWMExtendFrameIntoClientArea method. PInvoke dot net has the imports for this and all of the other DWM methods. However, some of these no longer work under Windows 10. The last time I used DWMExtendFrameIntoClientArea was on an earlier build of Windows 10 and it worked fine.