[英]How can I create a toggle button in Visual Studio with C#?
Is there a way to create a toggle button in C# windows forms?有没有办法在 C# windows forms 中创建切换按钮? I want to have is as such that when you toggle the button, the background changes from red to transparent.
我想要的是,当您切换按钮时,背景会从红色变为透明。 I've done that with a button but it would be better with toggle.
我已经用按钮完成了,但使用切换会更好。 Thanks
谢谢
According to your description, you want the background to change from red to transparent when you switch buttons.根据您的描述,您希望在切换按钮时将背景从红色变为透明。
You can try the following code to solve this problem.您可以尝试以下代码来解决此问题。
private void Form1_Load(object sender, EventArgs e)
{
radioButton1.Checked = true;
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
this.BackColor = Color.Red;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
this.TransparencyKey = Color.Turquoise;
this.BackColor = Color.Turquoise;
}
Result:结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.