本文介绍了表单上的TransparencyKey属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Windows窗体应用程序中使用Visual C#切换窗体背景透明度.
I would like to swith my form background transparency with Visual C# in a Windows Forms Application.
我用过
BackColor = Color.White;
TransparencyKey = Color.White;
现在,我想切换回不透明".我该怎么做?仅仅切换BackColor会使表单上的元素看起来很奇怪并且感觉很丑.我想有一种方法可以重置该属性.
Now I want to switch back to "not transparent". How can I accomplish that? Just switching the BackColor makes the elements on the form look strange and it feels ugly.I guess there is a way to reset the property.
推荐答案
如何将BackColor和TransparencyKey的先前值存储在局部变量中,并在要恢复为非透明状态时还原它们?例如:
How about storing the previous values of BackColor and TransparencyKey in local variables, and restoring them when you want to revert to non-transparent? For instance:
private Color _oldBG;
private Color _oldTPKey;
private void MakeTransparent() {
_oldBG = BackColor;
_oldTPKey = TransparencyKey;
BackColor = Color.White;
TransparencyKey = Color.White;
}
private void MakeNonTransparent() {
BackColor = _oldBG;
TransparencyKey = _oldTPKey;
}
这篇关于表单上的TransparencyKey属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!