如何更改Windows Forms Application工具条的颜色 [英] How to change the color of the toolstrip of windows Forms Application
本文介绍了如何更改Windows Forms Application工具条的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi Code Project读者,
我不知道如何在点击工具条按钮时更改工具条按钮的背景颜色...
我在工具条中有6个按钮。当我点击第3个按钮时,单独需要突出显示该按钮,直到点击下一个按钮。
先谢谢。
Hi Code Project readers,
I dont know how to change the background color of the toolstrip buttons when it is clicked...
I have 6 buttons in the toolstrip. when i click the 3rd button, that button alone need to be highlighted, till the next button is clicked.
Thanks in Advance.
推荐答案
步骤1.为每个按钮创建单击事件处理程序。
步骤2.对于5个按钮,添加取消突出显示按钮#3的代码。
步骤3.在按钮#3的处理程序中,添加突出显示按钮的代码(并可能去除所有其他按钮的亮点)
希望这是你的意思是。 : - )
Step 1. Create click event handlers for each button.
Step 2. For the 5 buttons, add code that de-highlights button #3.
Step 3. On the handler for button #3, add code that highlights the button (and possibly de-highlights all the others)
Hope this is what you meant. :-)
您需要为所有工具条按钮分配以下事件作为点击事件。
You need to assign below event as click event for all the toolstrip buttons.
Color NormalColor = SystemColors.Control;
Color HighlightColor = Color.Orange;
private void ToolStripButton_Click(object sender, EventArgs e)
{
ToolStripButton tsbtnTemp = sender as ToolStripButton;
toolStripButton1.BackColor = NormalColor;
toolStripButton2.BackColor = NormalColor;
toolStripButton3.BackColor = NormalColor;
toolStripButton4.BackColor = NormalColor;
toolStripButton5.BackColor = NormalColor;
toolStripButton6.BackColor = NormalColor;
tsbtnTemp.BackColor = HighlightColor;
}
这篇关于如何更改Windows Forms Application工具条的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文