如何在Windows Forms C#中切换可见性 [英] How to toggle visibility in Windows Forms C#
本文介绍了如何在Windows Forms C#中切换可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个标签,它们的可见度变化很大,而当我使用它们时,
I have a couple of labels that change visibility a lot and when they do I just use
Label1.Visible = true;
Label2.Visible = true;
Label3.Visible = true;
或
Label1.Visible = false;
Label2.Visible = false;
Label3.Visible = false;
因此,为了使我的代码更具可读性,我想将它们放在函数中.但是要做到这一点,我需要一个切换可见性的功能,而不是打开或关闭它们.这可能吗?
So to make my code more readable I want to put these in a function. But to do that I would need a function that toggles the visibility, not turns them on or off. Is this possible?
推荐答案
您的意思是简单地反转:
you mean simply invert:
void ToggleLabel(Label l)
{
l.Visible = ! l.Visible ;
}
这篇关于如何在Windows Forms C#中切换可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文