ghx88

动态改变控件的样式(Css)

(1)Style属性
         private void btnUpload_Click(object sender, System.EventArgs e)
      {
            Label1.Style("text-transform") = "Capitalize";      
        }

(2)cssClass属性
           <html>
                <head>
                    <style>
                            .myClass1
                                {
                                    font:18pt script;
                                    color: red;
                                 }
                           .myClass2
                                {
                                    font:24pt script;
                                    color: blue;
                                 }
                    </style>
                </head>
                    ……
                    ……
           </html>
         private void btnUpload_Click(object sender, System.EventArgs e)
      {
            Label1.cssClass ="myClass2";
        }

(3)生成Style类并赋给控件

        private void Button1_Click(object sender, System.EventArgs e)
        
{
            Style s 
= new Style();
            s.BackColor 
= Color.Yellow;
            s.ForeColor 
= Color.Red;
            s.BorderStyle 
= BorderStyle.Dashed;
            s.BorderWidth 
= new Unit(4);
            
this.TextBox1.ApplyStyle(s);
            
this.TextBox2.MergeStyle(s);
        }

ApplyStyle()方法覆盖了控件的旧样式,而MergeStyle()则不会覆盖现存的属性。
   

posted on 2006-03-13 12:28  ghx88  阅读(558)  评论(0编辑  收藏  举报

导航