如何使我的表单透明,但是我不能从中借鉴呢? [英] How do I make my form transparent, but what I draw on it not?
问题描述
我尝试将表单的不透明度设置为50%,然后在其上绘制一个字符串。看来,我在其上绘制的字符串也具有50%的不透明度。我将如何绘制一个不透明的字符串,但让表单背景显示为50%?
I tried setting the opacity of my form to 50%, and then drawing a string on it. It seems that the string I draw on it also has an opacity of 50%. How would I draw a non transparent string , but let the form background show through 50%?
如果可能的话,我也愿意在WPF中这样做,但是我
Would also be willing to do this in WPF if it is possible, but I would need explicit instructions or an example project as I have never done it before.
为澄清起见,我希望表单背景对下面的内容是不透明的80%黑色,然后我要在其上绘制文本等。并使它显示为100%不透明。
To clarify, I want the form background to be a black 80% opaque to what is underneath, and then I want to draw text, etc.. on it and have it appear 100% opaque.
推荐答案
在WPF中轻松完成:
- 在窗口上设置WindowStyle = None(注意:这是必需的,您不能具有透明度和标准Windows chrome)
- 在窗口上设置AllowsTransparency = True
- 使用透明的画笔在窗口上设置背景,例如Background = #AAFFFFFF
以下是一个快速示例:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300" AllowsTransparency="True" Background="#AAFFFFFF" WindowStyle="None">
<Grid>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" FontWeight="Bold">Hello World!</TextBlock>
</Grid>
现在显然,因为您如果禁用了标准Windows chrome,则需要提供自己的按钮才能关闭/最小化/最大化/拖动窗口。您可以自己轻松地完成此操作,也可以考虑购买类似 Blendables 之类的东西,您可以使用的Chromeless Window控件。
Now obviously, since you've disabled the standard Windows chrome, you will need to supply your own button to close/minimize/maximize/drag the window. You can do this pretty easily yourself or you could look into purchasing something like Blendables which comes with a "Chromeless Window" control that you could use.
这篇关于如何使我的表单透明,但是我不能从中借鉴呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!