C# Transparency in XP
I have a little splash window:
public partial class Splash : Form
{
bool painted = false;
public Splash()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
//
}
protected override void OnPaintBackgroun开发者_StackOverflow中文版d(PaintEventArgs e)
{
if (painted)
return;
Graphics gfx = e.Graphics;
gfx.DrawImage(Properties.Resources.Splash, ClientRectangle);
painted = true;
}
}
Properties.Resources.Splash
is a PNG with alpha, and displays beautifully on my Windows 7 development computer.
On the Windows XP target computers, however, there is no transparency; instead, the background of the image is black.
I know it's possible to display a transparent splash window in XP because I have seen it before. Is it possible to do it in .net? If so, how?
It can be done with WS_EX_LAYERED but requires some efforts and some P/Invoke: http://msdn.microsoft.com/en-us/library/ms997507.aspx
Also there is an older article here but don't know if it's still valid: http://www.codeproject.com/KB/cs/transparentwindowsincsharp.aspx
精彩评论