問題描述
我正在嘗試使 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作為啟動畫面的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!