半透明PNG作为启动画面

时间:2023-02-03
本文介绍了半透明PNG作为启动画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使 Splash Screen 4 成为 Win 应用程序.

I'm trying to make a Splash Screen 4 an Win application.

我的设置:

表单边框样式设置为无.起始位置是屏幕中心.表单的背景图片设置为 PNG 文件,带有圆角边缘和内置"投影.

form border style is set to none. start position is screen center. background image of the form is set to a PNG file, with rounded edges and a "build in" drop shadow.

在我设置的代码中:

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;

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

but when i test, it says that the form can't have a transparent background color.

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

i DO NOT want to set a transparency key, cuz it causes trouble with the dropschadow ( semi transparent part of the png )

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

also i dont want to set opacity to 0%, cuz it also effects my PNG.

事实上,我只希望我的 png 显示为窗口.另外,它上面还会有一些动态文本,将来还会有一个进程栏......

in fact i just want ONLY my png shown as the window. additionaly there will be some dynamic text on top of it and a process bar in the future...

有什么想法吗?如何判断表单可以有透明背景就像ADOBE PHOTOSHOP CS5的闪屏

Any ideas? how to tell the form that is CAN have transparent background like the splash screen of ADOBE PHOTOSHOP CS5

推荐答案

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

I spent a few hours looking for a way to do this in Win Forms as well so I thought I would share my solution.

我的初始屏幕图像是一个 .png,具有透明背景和在透明背景上延伸的各种阴影.使用不常见的颜色作为控件的背景以及透明度键会在半透明阴影下方留下难看的补丁.

My splash screen image is a .png with a transparent background and various shadows that extend over the transparent background. Using uncommon colors as the background of the control along with a transparency key left ugly patches underneath the semi-transparent shadows.

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

I was able to get the desired result by setting the background image of the form to the image I wanted to display and overriding the OnPaintBackground function like so:

    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 结果.

I'm only bumping this old thread because it's the top Google result for a few different keyword combos that I tried.

另请参阅 透明启动画面,这是我找到此解决方案的地方来自另一个 SO 帖子.

See also Transparent Splash Screen which is where I found this solution from another SO post.

这篇关于半透明PNG作为启动画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:打开隐藏的 Internet Explorer 窗口而没有获得焦点? 下一篇:Waitforexit 统一中断我正在运行的应用程序

相关文章

最新文章