【疯了C#】神奇的换肤(二)

昨天参照了网上的资料练习了换肤,今天进一步的实现选择换肤

其实很简单,需要实现的功能如下点击combobox中的不同项目然后面板会自动的切换到相应的界面主题。

界面如下:

下述代码参照 “张隽永” 博客,http://realzjy.blog.51cto.com/818594/165556

 public class ComboBoxItem
        {
            private string _text = null;
            private object _value = null;
            public string Text { get { return this._text; } set { this._text = value; } }
            public object Value { get { return this._value; } set { this._value = value; } }
            public override string ToString()
            {
                return this._text;
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            ComboBoxItem bt1 = new ComboBoxItem();
            ComboBoxItem bt2 = new ComboBoxItem();
            ComboBoxItem bt3 = new ComboBoxItem();
            ComboBoxItem bt4 = new ComboBoxItem();
            bt1.Text = "皮肤1";
            bt1.Value = "皮肤1";
            bt2.Text = "皮肤2";
            bt2.Value = "皮肤2";
            bt3.Text = "皮肤3";
            bt3.Value = "皮肤3";
            bt4.Text = "皮肤4";
            bt4.Value = "皮肤4";
            Type.Items.Add(bt1);
            Type.Items.Add(bt2);
            Type.Items.Add(bt3);
            Type.Items.Add(bt4);
        }

本段代码是对Combobox进行load时的显示初始化。

点击combobox 切换切换index时的code

  private void Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            string[] A = { "皮肤1", "皮肤2", "皮肤3", "皮肤4" };
            Type.Text = A[Type.SelectedIndex];
        }

点击确定按钮执行换肤动作的code

private void Confirm_Click(object sender, EventArgs e)
        {
            switch(Type.Text)
            {
                case "皮肤1":
                    this.skinEngine1.SkinFile="DiamondBlue.ssk";
                    break;
                case "皮肤2":
                    this.skinEngine1.SkinFile="SportsBlue.ssk";
                    break;
                case "皮肤3":
                    this.skinEngine1.SkinFile="SportsCyan.ssk";
                    break;
                case "皮肤4":
                    this.skinEngine1.SkinFile="diamondgreen.ssk";
                    break;
            }                   
       
        }

代码写的很垃圾,当然本文的主要目的也仅仅是为了亲手实现这个功能。

切换index

posted @ 2015-03-05 09:38  梦小邪  阅读(667)  评论(0编辑  收藏  举报