更新时间:2023-01-26 12:03:44
我也花了几个小时在 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.