gpt4 book ai didi

windows-7 - .NET Framework 4.0 和绘制 Aero Glass 问题

转载 作者:行者123 更新时间:2023-12-03 17:20:53 26 4
gpt4 key购买 nike

在我的应用程序中,我有一个表单,我通过使用 DWM API 的方法 DwmExtendFrameIntoClientArea 来调整表单以扩展 Aero Glass 标题栏的高度,以便我的表单客户区的一部分绘制在 Aero 框架上。为了达到这种效果,我还在客户区的玻璃框“上方”部分绘制了一个黑色矩形,使其看起来透明,正如许多在线文章所建议的那样。这在 Windows Vista/Windows 7 下工作得很好,但是当我下载 VS 2010 并使用 .NET Framework 4.0 作为我的目标框架来构建我的应用程序时,这种方法不再有效。问题是黑色矩形是可见的,即在 Aero 玻璃上绘图时不再认为黑色是透明的。有没有人知道这可能有什么问题以及如何克服?

最佳答案

此处描述了此问题的答案:http://msdn.microsoft.com/en-us/magazine/cc163435.aspx#S6与 C# 的解决方案。

链接页面的摘录(如果链接已关闭):

Using glass as a background on your window is a bit tricky. If you render anything naturally opaque (such as GDI functions), you'll get your item rendered on glass, though sometimes with unexpected results. If you want to actually blend rendering into the glass surface, you'll need to take advantage of functionality that utilizes the alpha channel of colors, such as GDI+, Windows Presentation Foundation, or the Windows XP Theme API.

One particular gotcha is that rendering a GDI item in black uses the bit pattern 0x00000000-which also happens to be a completely transparent black if you are using an alpha channel. This means that if you draw with a black GDI brush or pen you'll get a transparent color, not a black one. The biggest problem this presents is when you try to use the default text color in a control of a text label that sits on the glass area. Since the default text color is usually black, the DWM will consider this to be transparent and the text will be written in the glass incorrectly.



以及 WinForms 的解决方案:

Happily, there are a number of ways around this problem. Using owner-draw controls is one. Rendering to a bitmap that has an alpha channel is another. Fortunately, the easiest way to get text on controls is to let the .NET Framework 2.0 use GDI+ for you. This is easily accomplished by setting the UseCompatibleTextRendering property on your controls. By default, this property is set to false so that controls written for previous versions of the .NET Framework will render the same. But if you set it to true, your text will come out looking correct. You can set the property globally with the Application.SetUseCompatibleTextRenderingDefault method. If you're using Visual Studio® 2005, the template code will include a call to set compatible text-rendering to false in the main routine before your form is created. You can just edit this to set it to true as shown below and all your controls will look correct when written on a glass window.


static void Main()
{
Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(true); // this line fixes an issue

Application.Run(new GlassForm());
}

关于windows-7 - .NET Framework 4.0 和绘制 Aero Glass 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2666979/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com