gpt4 book ai didi

c# - 半透明 PNG 作为启动画面

转载 作者:行者123 更新时间:2023-11-30 22:30:24 32 4
gpt4 key购买 nike

我正在尝试将 Splash Screen 4 制作成 Win 应用程序。

我的设置:

表单边框样式设置为无。起始位置是屏幕中心。表单的背景图像设置为 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;

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

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

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

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

有什么想法吗?如何判断窗体是否可以有透明背景像ADOBE PHOTOSHOP CS5的闪屏

最佳答案

我也花了几个小时寻找在 Win Forms 中执行此操作的方法,所以我想我会分享我的解决方案。

我的初始屏幕图像是一个 .png 文件,具有透明背景和在透明背景上延伸的各种阴影。使用不常见的颜色作为控件的背景以及透明键在半透明阴影下留下丑陋的斑 block 。

我能够通过将表单的背景图像设置为我想要显示的图像并覆盖 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 帖子中找到这个解决方案的地方。

关于c# - 半透明 PNG 作为启动画面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9666910/

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