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

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

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)