標籤:
昨天參照了網上的資料練習了換膚,今天進一步的實現選擇換膚
其實很簡單,需要實現的功能如下點擊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
【瘋了C#】神奇的換膚(二)