asp.net伺服器控制項屬性設定

來源:互聯網
上載者:User

作個記號,以後會經常用到的屬性設定.

我們可以通過編程設定 Web 伺服器控制項屬性,以便在運行時更改控制項的外觀和行為。

本文以下內容提供了有關設定不同屬性類型的詳細資料:

1.  設定基於單值或枚舉的屬性:
       
如果 Web 伺服器控制項屬性的資料類型為基元(String、Boolean 或數字類型)然後您只需將其指定到屬性即可設定相應屬性值。同樣,如果屬性值在枚舉類中定義,您可以只將該枚舉指定到屬性。     

       1.1  設定基於單值的屬性值 
             
            ■  將該值指定為文字或變數,如下例所示:
                     
                 Label1.Text = "Hello";
                 DataGrid1.PageSize = 5;
        
            ■  設定基於枚舉的屬性值 

                  // Uses TextBoxMode enumeration
                  this.TextBox1.TextMode = TextBoxMode.SingleLine;
                  // Uses ImageAlign enumeration
                  this.Image1.ImageAlign = ImageAlign.Middle;

  2.  設定單位屬性:
        
寬度、高度和相似屬性是按單位設定的。單位實現為對象(Unit 結構),允許您採用多種方式指定值和度量單位。      
        2.1  設定基於單位的屬性 
          
               // Default is pixels.
               TextBox1.Width = new Unit(100);
               TextBox1.Width = new Unit(100, UnitType.Pixel);
               TextBox1.Width = new Unit("100px");
               // Centimeters
               TextBox1.Width = new Unit("2cm");
               TextBox1.Width = new Unit(10, UnitType.Percentage);
               TextBox1.Width = new Unit("10%");   

3.  設定顏色屬性      
      要設定顏色(例如 BackColor 屬性)屬性,您需要分配對 Color 對象的引用。
     
      Button1.BackColor = Color.FromName("Red");

            

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.