問題描述
我想讓我的 windows 窗體透明,所以刪除了邊框、控件和只留下窗體框的所有內容,然后我嘗試將 BackColor 和 TransparencyKey 設置為透明但它沒有成功,因為 BackColor 不接受透明顏色.在四處搜索后,我在 msdn 上找到了這個:
I wanted to make my windows form transparent so removed the borders, controls and everything leaving only the forms box, then I tried to the BackColor and TransparencyKey to transparent but it didnt work out as BackColor would not accept transparent color. After searching around I found this at msdn:
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;
this.TransparencyKey = BackColor;
不幸的是,它也不起作用.我仍然得到灰色或任何其他選定的顏色背景.
Unhappyly it did not work either. I still get the grey or any other selected color background.
我想做的就是讓窗體透明,這樣我就可以使用一個背景圖像,就好像它是我的窗體一樣.
All I wanted to do is to have the windows form transparent so I could use a background image that would act as if it was my windows form.
我在這里搜索了很多關于不透明度的主題,這不是我想要的,還看到了一些關于我正在嘗試但尚未找到答案的方法.
I searched around here and saw many topics in regards opacity which is not what I am looking for and also saw some in regards this method I was trying but have not found an answer yet.
希望任何人都可以照亮我的道路.
Hope anyone can light my path.
更新:
問題解決后刪除圖片
推薦答案
我之前使用的方式是對BackColor使用一種百搭的顏色(沒有人會使用的顏色),然后設置透明度鍵到那個.
The manner I have used before is to use a wild color (a color no one in their right mind would use) for the BackColor and then set the transparency key to that.
this.BackColor = Color.LimeGreen;
this.TransparencyKey = Color.LimeGreen;
這篇關于winforms透明背景?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!