简体   繁体   English

如何使用 C# 在 Visual Studio 中创建切换按钮?

[英]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.

相关问题 如何在Visual Studio / WPF / C#中创建“分配按钮” texbox? - How to create a “assign button” texbox in visual studio / wpf / c#? 如何在Windows窗体中将.png文件用作按钮? (在C#中 - visual studio 2013) - How can I use a .png file as a button in Windows Form ? ( in C# - visual studio 2013 ) 我如何在没有点击按钮的情况下调用 function? (视觉工作室 c# 2017) - How can i call a function without click button ? (visual studio c# 2017) 如何使用 Visual Studio C# WinForms 中的变量创建 Unicode 字符串? - How can I create a Unicode string using variables in Visual Studio C# WinForms? 如何在 Visual Studio 的 C# 中创建服务引用? - How do I create a Service Reference in C# in Visual Studio? 如何在 Visual Studio C# 中创建表单实例? - How do I create an instance of a form in Visual Studio C#? 如何在Visual Studio C中创建“项目概述”# - How do I create a “Project overview” in Visual Studio C# 如何在Visual Studio中切换自动制表-C# - How to toggle automatic tabbing in visual studio - C# 如何在 C# (Visual Studio) 中进行热键控制 - How can I make Hotkey control at C# (Visual Studio) 如何在 Visual Studio 2017 中使用 C# 8? - How can I use C# 8 with Visual Studio 2017?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM