Asp.net伺服器控制項樣式使用兩例

來源:互聯網
上載者:User

方法一:

.aspx代碼

<form id="Form1" method="post" runat="server">
   <FONT face="宋體">
    <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 256px; POSITION: absolute; TOP: 112px"
     runat="server"></asp:TextBox>
    <asp:Button id="Button1" style="Z-INDEX: 104; LEFT: 256px; POSITION: absolute; TOP: 144px" runat="server"
     Text="設 置"></asp:Button>
    <asp:Label id="Label2" style="Z-INDEX: 103; LEFT: 256px; POSITION: absolute; TOP: 80px" runat="server">動態設定TextBox的樣式</asp:Label>
    <asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 256px; POSITION: absolute; TOP: 184px" runat="server"></asp:Label></FONT>
  </form>

.aspx.cs代碼

private void Button1_Click(object sender, System.EventArgs e)
  {//設定樣式
   TextBox1.Style.Add("width",TextBox1.Text.ToString());
   Label1.Text="寬度"+TextBox1.Style["width"].ToString();
  }

方法二:

.aspx代碼

<form id="Form1" method="post" runat="server">
   <asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 264px; POSITION: absolute; TOP: 48px" runat="server">動態設定伺服器控制項的樣式</asp:Label>
   <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 264px; POSITION: absolute; TOP: 112px" runat="server"
    Text="設 置"></asp:Button>
   <asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 264px; POSITION: absolute; TOP: 80px" runat="server"></asp:TextBox>
  </form>

.aspx.cs代碼

private void Button1_Click(object sender, System.EventArgs e)
  {//設定樣式
   Style style=new Style();
   style.BorderColor=Color.Black;
   style.BorderStyle=BorderStyle.Inset;
   style.BorderWidth=new Unit(1);
   TextBox1.ApplyStyle(style);
  }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.