我正在開發一個項目在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. C#Windows應用程序attachmentFilename
- 2. C#Windows應用程序
- 3. Windows應用程序C
- 4. C#Windows應用程序
- 5. c#windows應用程序中的線程
- 6. 將C#(Windows應用程序)轉換爲commadline應用程序?
- 7. 從Windows窗體應用程序C控制檯應用程序#
- 8. 使用C#Windows窗體應用程序
- 9. 用C++開發Windows phone應用程序
- 10. C#windows phone 8應用程序段
- 11. iTextSharp C#windows store應用程序
- 12. 從C#.NET Windows應用程序
- 13. c#windows桌面應用程序.MVS
- 14. Windows 8應用程序全屏webview C#
- 15. Google Search in c#windows應用程序
- 16. 部署Release C#windows應用程序
- 17. C#MVC的Windows應用程序
- 18. 備份C#Windows應用程序數據
- 19. C#Windows應用程序部署
- 20. Windows 10 UWP應用程序c#打印
- 21. 爲Windows XP編譯C#應用程序
- 22. Windows應用程序廓 - C++埃克
- 23. C# - 捕獲Windows應用程序輸出
- 24. Windows 8/C#應用程序到PDF
- 25. 無法從Windows應用程序C#
- 26. C#控制檯和Windows應用程序
- 27. C#中的Windows應用程序?
- 28. 創建Windows窗體C#應用程序
- 29. C#Web服務與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