当前位置:编程学习 > C#/ASP.NET >>

C# 动态生成textbox,Combobox等控件实例

  1. public static void SetControlsReadOnly(Control control)
  2.         {
  3.             foreach (Control c in control.Controls)
  4.             {
  5.                 if (c is Panel)
  6.                 {
  7.                     SetControlsReadOnly(c);
  8.                 }
  9.                 /*
  10.                 if (c is GroupBox)
  11.                 {
  12.                     SetControlsReadOnly(c);
  13.                 }
  14.                 if (c is tabControl)
  15.                 {
  16.                     SetControlsReadOnly(c);
  17.                 }
  18.                  */
  19.                 if (c is TabPage)
  20.                 {
  21.                     SetControlsReadOnly(c);
  22.                 }
  23.                 if (c is TextBox)
  24.                 {
  25.                     //   它是   TextBox,   要干什么随便你 
  26.                     System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)c;
  27.                     //tb.ReadOnly = true;
  28.                     tb.Enabled = false;
  29.                 }
  30.                 else if (c is ComboBox)
  31.                 {
  32.                     System.Windows.Forms.ComboBox cb = (System.Windows.Forms.ComboBox)c;
  33.                     cb.Enabled = false;
  34.                 }
  35.             }
  36.         }

补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,