本文介绍了如何制作真正透明的控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个只显示大纲的控件,我需要将它放在一个显示视频的控件上.如果我让我的控件透明,那么视频就会被遮挡,因为透明控件是由它们的父控件绘制的,而视频不是由控件绘制的;它使用 DirectShow 或其他库显示,因此父控件会绘制其 BackColor.

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?

rslite 是对的——尽管你甚至不需要像他的例子那样使用 PInvoke——Control.Region 属性就完全足够了.

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.

推荐答案

你可以尝试制作一个里面有洞的 Region,并用 SetWindowRgn 设置控制区域.

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.

这篇关于如何制作真正透明的控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:54