winforms透明背景?

Transparent background on winforms?(winforms透明背景?)
本文介绍了winforms透明背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想让我的 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透明背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to know if a field is numeric in Linq To SQL(如何在 Linq To SQL 中知道字段是否为数字)
Extract sql query from LINQ expressions(从 LINQ 表达式中提取 sql 查询)
LINQ Where in collection clause(LINQ Where in collection 子句)
Orderby() not ordering numbers correctly c#(Orderby() 没有正确排序数字 c#)
Why do I get quot;error: ... must be a reference typequot; in my C# generic method?(为什么我会收到“错误:...必须是引用类型?在我的 C# 泛型方法中?)
Strange LINQ Exception (Index out of bounds)(奇怪的 LINQ 异常(索引越界))