CSDN博客

img chenshuaijunsfsf

为多个控件赋值!

发表于2008/10/3 9:45:00  222人阅读

 使用Hashtable来放控件;

 

int[] i = new int[] { 0, 1, 1, 1, 1 };//1表示要处理的控件
            hashtable = new Hashtable();
            int k = 0;
            foreach (Control con in Controls)
            {
                k++;
                object obj = (object)con;
                hashtable.Add(k.ToString(), obj);
            }
            for (int j = 0; j < i.Length; j++)
            {
                object obj = hashtable[j.ToString()];//得到对象
                if (i[j] == 1)
                {
                    try
                    {
                        if (obj is Button)//判断
                        {
                            Button btn = (Button)obj;
                            btn.Visible = false;
                        }
                        if (obj is TextBox)
                        {
                            TextBox tb = (TextBox)obj;
                            tb.Visible = false;
                        }
                    }
                    catch (Exception er)
                    {
                        MessageBox.Show(er.Message);
                    }


                }

            }

阅读全文
0 0

相关文章推荐

img
取 消
img