views:

737

answers:

4

I need to make a Control which shows only an outline, and I need to place it over a control that's showing a video. If I make my Control transparent, then the video is obscured, because transparent controls are painted by their parent control and the video isn't painted by the control; it's shown using DirectShow or another library, so instead the parent control paints its BackColor.

So - can I make a control that doesn't get painted at all, except where it's opaque? That way, the parent control wouldn't paint over the video.

I know I could make the border out of four controls (or more if I want it dashed) but is it possible to do what I want using just one control?

+3  A: 

You could try to make a Region with a hole inside and set the control region with SetWindowRgn.

Here is an example (I couldn't find a better one). The idea is to create two regions and subtract the inner one from the outer one. I think that should give you what you need.

rslite
A: 

You could try setting the Form.TransparencyKey property. Failing that, you could use DirectX to get access to the frame buffer and draw directly to it.

Skizz

Skizz
I misread the question. Although forms can be made transparent and show video through them, doing the same with a control/child form is much harder and does require the controls under the transparent control to raise paint events on their update.
Skizz
A: 

rslite is right - although you don't even need to go so far as to use PInvoke like his example does - the Control.Region property is entirely sufficient.

Simon
A: 

Hi,

I try to do the same in VB.

I have a custom control drawing a grid, which should be visible over a vlc-video. When I start playback the grid disapears, stopping playback brings it back again.

I do:

GridCTRL.BackColor = Color.Transparent
GridCTRL.Parent = AxVLCPlugin

and in the code of the gridCTRL:

MyBase.SetStyle(ControlStyles.SupportsTransparentBackColor, True)

It work, but not in combination with video playback. Can someone please explain the solution again for me?

Thanks,

Norbert