程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C# 動態生成textbox,Combobox等控件實例

C# 動態生成textbox,Combobox等控件實例

編輯:C#入門知識

  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.         }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved