首页 > 编程 > C# > 正文

c#一种简单快速改变窗体风格和肤色的方法源码及其控件

2023-05-10 18:49:30
字体:
来源:转载
供稿:网友

有时我们在设计C#程序时,很想改变一下窗体的风ge和肤色,显得非常炫丽而且符合不同人对肤色的要求,本文就介绍了如何在C#中改变窗体肤色和风ge的程序。

C#应用程序启动时:

Application.Run(new Form1());

新建了一个窗体,但是很难在窗体建立后随意改变窗体风ge和颜色,经过一番试验发现了如下方法可以在窗体建立后随意改变窗体的风ge和颜色。

首先添加一个timer1,下面是timer的代码改变了skinEngine1.SkinFile的属性(kinEngine1是一个改变肤色的扩展控件),注意要把kinEngine1.SkinFile的属性改成你SkinFile所在的绝对路径,SkinFile在附件里面的skin文件夹中。本例中还用到了其他的扩展控件以及本例源码都在附件中。

private void timer1_Tick(object sender, EventArgs e)
{
    this.count = this.count + 1;
    if (this.count >= 26) { this.count = 0; }
    hsttextbox1.Text = (this.count).ToString("#0");
    switch (this.count)
    {
       case 0:
           this.skinEngine1.SerialNumber = "";
           this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//Calmness.ssk";
         //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
           break;
        case 1:
            //this.Close();
            this.skinEngine1.SerialNumber = "";
            this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//CalmnessColor1.ssk";
            //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
            new Form1();
            break;
       case 2:
            this.skinEngine1.SerialNumber = "";
            this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//CalmnessColor2.ssk";
            //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
            new Form1();
            break;
       case 3:
           this.skinEngine1.SerialNumber = "";
           this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//DeepCyan.ssk";
          //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
          new Form1();
          break;
       case 4:
          this.skinEngine1.SerialNumber = "";
          this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//DeepGreen.ssk";
         //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
         new Form1();
         break;
      case 5:
          this.skinEngine1.SerialNumber = "";
          this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//DeepOrange.ssk";
          ///this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
          new Form1();
          break;
      case 6:
          this.skinEngine1.SerialNumber = "";
         this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//DiamondBlue.ssk";
          //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
          new Form1();
          break;
      case 7:
          this.skinEngine1.SerialNumber = "";
          this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//DiamondGreen.ssk";
         //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
         new Form1();
         break;
     case 8:
        this.skinEngine1.SerialNumber = "";
         this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//Eighteen.ssk";
        //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
         new Form1();
         break;
     case 9:
        this.skinEngine1.SerialNumber = "";
        this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//EighteenColor1.ssk";
        //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
        new Form1();
        break;
     case 10:
         this.skinEngine1.SerialNumber = "";
         this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//EighteenColor2.ssk";
         //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
         new Form1();
         break;
     case 11:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//Emerald.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
                case 12:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//EmeraldColor1.ssk";
                   // this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();break;
                case 13:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//EmeraldColor2.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();break;
                case 14:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//EmeraldColor3.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
                case 15:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//GlassBrown.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
                case 16:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//GlassGreen.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
                case 17:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//GlassOrange.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
                case 18:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//Longhorn.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
                case 19:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//MacOS.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
                case 20:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//Midsummer.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
                case 21:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//MidsummerColor1.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
                case 22:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//MidsummerColor2.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
                case 23:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//MidsummerColor3.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
                case 24:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//MP10.ssk";
                   // this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
                case 25:
                    this.skinEngine1.SerialNumber = "";
                    this.skinEngine1.SkinFile = "C://Documents and Settings//vincent//My Documents//Visual Studio 2005//Projects//clourfulskin//clourfulskin//skin//MSN.ssk";
                    //this.skinEngine1.SkinStreamMain = ((System.IO.Stream)(resources.GetObject("skinEngine1.SkinStreamMain")));
                    new Form1();
                    break;
            }
            //InitializeComponent();
        }

到此为止可以改变26种颜色。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表