我想点击它时更改按钮颜色 [英] i want to change the button color wheni click on it
本文介绍了我想点击它时更改按钮颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在C#的Windows应用程序中点击它时更改按钮的颜色。有人可以帮帮我吗?
解决方案
受保护 void Button1_Click( object sender,EventArgs e)
{
if (Button.BackColor!= Color.Red)
Button1.BackColor = Color。红色;
else
Button1.BackColor = Color.Blue;
}
您好,
添加请点击
所有按钮的事件处理程序:
public Form1()
{
InitializeComponent();
button1.Click + = new EventHandler(allButtons_Click);
button2.Click + = new EventHandler(allButtons_Click);
button3.Click + = new EventHandler(allButtons_Click);
// 为所有按钮执行此操作
} $ p $然后,创建allButtons_Click
函数:
void allButtons_Click( object sender,EventArgs e)
{
Button senderBtn = sender as 按钮;
senderBtn.ForeColor = Color.Red; // 设置按钮的前色
senderBtn.BackColor = Color.Orange; // 设置按钮的背景颜色
}
希望这有帮助。
你好
如果你想改变它的答案除了答案精美:
Visual Studio C#Windows表格......更改按钮颜色?
I want to change the color of the button when I click on it in windows application of C#.. Anybody can help me?
解决方案
protected void Button1_Click(object sender, EventArgs e) { if(Button.BackColor != Color.Red) Button1.BackColor = Color.Red; else Button1.BackColor = Color.Blue; }
Hi,
Add aClick
event handler to all your buttons:
public Form1() { InitializeComponent(); button1.Click += new EventHandler(allButtons_Click); button2.Click += new EventHandler(allButtons_Click); button3.Click += new EventHandler(allButtons_Click); // do this for all your buttons }
Then, create theallButtons_Click
function:
void allButtons_Click(object sender, EventArgs e) { Button senderBtn = sender as Button; senderBtn.ForeColor = Color.Red; // set the fore color of the button senderBtn.BackColor = Color.Orange; // set the back color of the button }
Hope this helps.
Hello
In addition to the answers if you want to change it beautifully:
Visual Studio C# Windows Forms… changing button color?
这篇关于我想点击它时更改按钮颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文