我正在开发一个项目在C#Windows应用程序(赢得窗体),因为我需要创建一个函数来更改所有按钮的背景颜色使用按钮鼠标在单个Win窗体事件C#Windows应用程序
回答
可更换式按钮的所有控制:钩
for (int i = 0; i < Controls.Count; i++)
if (Controls[i] is Button) Controls[i].BackColor = Color.Blue;
例子:
MouseEnter += new EventHandler(delegate(object sender, EventArgs e)
{
SetButtonColour(Color.Blue);
});
MouseLeave += new EventHandler(delegate(object sender, EventArgs e)
{
SetButtonColour(Color.Red);
});
public void SetButtonColour(Color colour)
{
for (int i = 0; i < Controls.Count; i++)
if (Controls[i] is Button) Controls[i].BackColor = Color.Blue;
}
罚款,这是非常有用的 – 2010-11-09 11:35:42
假设你只是改变你自己的应用程序,这并不难。
在鼠标事件,在窗体控件属性和那些按钮所有项目只是循环,改变背景色。您需要编写递归函数来查找所有按钮,因为Panel(或GroupBox等)包含其所有控件的Controls属性。
一样,只有我在做,所有的按钮都放在组框里面,我已经tryed,对于文本框下面的代码,但使用改变背景色鼠标悬停事件是对我有些临界 公共静态无效Fungbstyle(分组框中gbsty){ gbsty.BackColor = Color.LightSteelBlue; gbsty.Cursor = Cursors.AppStarting; 的foreach(控制CNN在gbsty.Controls){ 如果(CNN是文本框){ cnn.BackColor = Color.LightCyan; cnn.Cursor = Cursors.PanNW; cnn.Font = new Font(cnn.Font,FontStyle.Italic); cnn.Width = 156; }}} – 2010-08-26 13:59:20
事情是这样的:
public partial class Form1 : Form
{
Color defaultColor;
Color hoverColor = Color.Orange;
public Form1()
{
InitializeComponent();
defaultColor = button1.BackColor;
}
private void Form1_MouseHover(object sender, EventArgs e)
{
foreach (Control ctrl in this.Controls)
{
if (ctrl is Button)
{
ctrl.BackColor = hoverColor;
}
}
}
private void Form1_MouseLeave(object sender, EventArgs e)
{
foreach (Control ctrl in this.Controls)
{
if (ctrl is Button)
{
ctrl.BackColor = defaultColor;
}
}
}
}
- 1. Windows应用程序C
- 2. C#Windows应用程序attachmentFilename
- 3. C#Windows应用程序
- 4. C#Windows应用程序
- 5. c#windows应用程序中的线程
- 6. 用C++开发Windows phone应用程序
- 7. 将C#(Windows应用程序)转换为commadline应用程序?
- 8. C#Windows应用程序中的PayPal API
- 9. 在Windows启动应用程序C#
- 10. Windows 10 UWP应用程序c#打印
- 11. c#windows桌面应用程序.MVS
- 12. Mergesort C++ Windows窗体应用程序
- 13. C#控制台和Windows应用程序
- 14. C#MVC的Windows应用程序
- 15. C#Windows窗体应用程序关闭
- 16. c中的Windows服务应用程序#
- 17. Windows 8/C#应用程序到PDF
- 18. C#中的Windows应用程序?
- 19. 备份C#Windows应用程序数据
- 20. Windows应用程序廓 - C++埃克
- 21. 为Windows Mobile开发应用程序,C#
- 22. 无法从Windows应用程序C#
- 23. Windows C++应用程序崩溃
- 24. 部署Release C#windows应用程序
- 25. C#Web服务与Windows应用程序
- 26. linux-windows跨C++应用程序
- 27. 为Windows编译Linux应用程序(C)
- 28. C#windows桌面应用程序
- 29. 从(C#)的Windows应用程序
- 30. MongoDB for Windows C#.Net应用程序
您正在使用的WinForms或WPF?什么是“lidos”? – Tokk 2010-08-26 13:35:03
你将需要更多地解释这个问题。按钮是否仅在您的应用中更改?或者你是否在更换其他应用程序的按钮? – 2010-08-26 13:37:36
自己明确提及这是Windows应用程序,如果这是WPF控件意味着我需要编写WPF控件 – 2010-08-26 13:46:37