本文介绍了如何对控制数组的其他成员采取行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public void ClickHandler(Object sender, System.EventArgs e)
{
int index;
int curr_index;
if (((System.Windows.Forms.Button)sender).Text == "0")
{
((System.Windows.Forms.Button)sender).BackColor = System.Drawing.Color.DarkKhaki;
index = this.List.IndexOf(sender);
// change color of neighbor above and to the left
curr_index = index - 33;
foreach (System.Windows.Forms.Button butt in HostForm.Controls)
{
if (butt.Text == "0")
{
butt.BackColor = System.Drawing.Color.Black; // this turns all buttons with Text == 0 to black -- i want to turn only the button with index 33 less than butt to black
}
}
}
}
推荐答案
public void ClickHandler(Object sender, System.EventArgs e)
{
int index;
int curr_index;
if (((System.Windows.Forms.Button)sender).Text == "0")
{
((System.Windows.Forms.Button)sender).BackColor = System.Drawing.Color.DarkKhaki;
index = this.List.IndexOf(sender);
curr_index = index - 33;
this.List[curr_index].BackColor = System.Drawing.Color.Black;
}
}
这篇关于如何对控制数组的其他成员采取行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!