半透明PNG作为启动画面

时间:2012-03-12 12:21:32

标签: c# background png transparent splash-screen

我正在尝试将Splash Screen 4设为Win应用程序。

我的设置:

表单边框样式设置为none。开始位置是屏幕中心。 窗体的背景图像设置为PNG文件,带有圆边和“内置”阴影。

在代码中我设置了:

this.SetStyle( ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle( ControlStyles.UserPaint, true);
this.SetStyle( ControlStyles.DoubleBuffer, true);
this.SetStyle( ControlStyles.SupportsTransparentBackColor, true);

this.AllowTransparency = true;
this.BackColor = Color.Transparent;

但是当我测试时,它表示表单不能具有透明的背景颜色。

我不想设置透明度键,因为它会导致dropchadow(png的半透明部分)出现问题

我也不想将不透明度设置为0%,因为它也会影响我的PNG。

事实上,我只想把我的png显示为窗口。另外,它上面会有一些动态文本和未来的过程栏......

有什么想法吗?如何告诉CAN表格具有透明背景如ADOBE PHOTOSHOP CS5的启动画面

2 个答案:

答案 0 :(得分:3)

我花了几个小时在Win Forms中寻找一种方法,所以我想我会分享我的解决方案。

我的启动画面图像是一个带有透明背景和各种阴影的.png,它们在透明背景上延伸。使用不常见的颜色作为控件的背景以及透明度键,在半透明阴影下方留下难看的补丁。

我能够通过将表单的背景图像设置为我想要显示的图像并覆盖OnPaintBackground函数来获得所需的结果:

    bool painted = false
    protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
    {
        if (painted) return;
        e.Graphics.DrawImage(BackgroundImage, new System.Drawing.Point(0, 0));
        painted = true;
    }

我只是碰到了这个旧帖子,因为它是我尝试过的几个不同关键词组合的Google搜索结果。

另请参阅Transparent Splash Screen,这是我从其他SO帖子中找到此解决方案的地方。

答案 1 :(得分:0)

以下是WPF启动画面的简单示例。这一切都在XAML中。我没有写一行C#来使它工作。

<Window x:Class="WpfSplashScreen.SplashScreen"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        WindowStyle="None" Background="Transparent" AllowsTransparency="True"
        ShowInTaskbar="False" SizeToContent="WidthAndHeight"
        WindowStartupLocation="CenterScreen">
    <Image Source="logo.png" Stretch="None" />
</Window>

这只是一个例子,需要更多代码才能使它变得有用,但这就是WPF中闪屏的容易程度。

相关问题