c# 遍历按钮

这几天一直为遍历控件头疼,最后才发现容器没选择正确是问题的所在

        private void Clickclear1()//清除面板1按下状态
        {

            foreach (Control but in splitContainer1.Panel1.Controls)
            {

                if (but.GetType().ToString() == "System.Windows.Forms.Button")
                {
                    (but as Button).FlatStyle = FlatStyle.Standard;
                }
            }
        }

红字是按钮所在正确位置

另外 but.GetType().ToString() == "System.Windows.Forms.Button"与but.GetType() == typeof(Button)效果相同

你可能感兴趣的:(c# 遍历按钮)