半透明PNG作为启动画面
- 作者: 原来名字可以那么
- 来源: 51数据库
- 2023-02-08
问题描述
我正在尝试使 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.
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源