我有一个小飞溅窗口:
public partial class Splash : Form
{
bool painted = false;
public Splash()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
//
}
protected override void OnPaintBackground(PaintEventArgs e)
{
if (painted)
return;
Graphics gfx = e.Graphics;
gfx.DrawImage(Properties.Resources.Splash, ClientRectangle);
painted = true;
}
}
Properties.Resources.Splash
是一个带有 alpha 的 PNG,在我的 Windows 7 开发计算机上显示得很漂亮。
然而,在 Windows XP 目标计算机上,没有透明度;相反,图像的背景是黑色的。
我知道在 XP 中显示透明启动窗口是可能的,因为我以前见过它。是否可以在 .net 中执行?如果是,怎么办?
最佳答案
这可以通过 WS_EX_LAYERED 完成,但需要一些努力和一些 P/Invoke:http://msdn.microsoft.com/en-us/library/ms997507.aspx
这里还有一篇旧文章,但不知道它是否仍然有效:http://www.codeproject.com/KB/cs/transparentwindowsincsharp.aspx
关于XP 中的 C# 透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6052454/