程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C#開發WPF/Silverlight動畫及游戲系列教程(Game Tutorial):(四十四)(2)

C#開發WPF/Silverlight動畫及游戲系列教程(Game Tutorial):(四十四)(2)

編輯:關於C語言

在QXTabControl中包含一個List<QXIcon> tabItemList = new List<QXIcon>();用於管理現有的所有選項卡;我還模仿TabControl在QXTabControl中創建SelectionChanged事件:

public delegate void SelectionChangedEventHandler(object sender, QXIcon tabItem);
public event SelectionChangedEventHandler SelectionChanged;

當某個選項卡被點擊時,觸發該事件:

……
tabItem.MouseLeftButtonDown += (sender, e) => {
 foreach (QXIcon icon in tabItemList) {
  if (icon == sender) {
   icon.Hit = true;
   icon.Container.Background = icon.HitNewBodySource;
  } else {
   icon.Hit = false;
   icon.Container.Background = icon.BodySource;
  }
 }
 SelectionChanged(this, sender as QXIcon);
 e.Handled = true;
};
……

這樣我們就可以在游戲窗口中對已創建的選項卡控件注冊SelectionChanged事件了:

//主角屬性選項卡內容
QXTabControl tc = new QXTabControl() {
 TabItemOrientation = OrIEntation.Horizontal,
 TabItemHeight = 28,
 BodyLeft = -4,
 BodyTop = 27
};
//添加4個選項卡
tc.AddItem(63, 28, 1, "/Image/Icon/39.png", "/Image/Icon/40.png", "/Image/Icon/41.png", "/Image/Icon/42.png", "屬  性");
tc.AddItem(63, 28, 1, "/Image/Icon/39.png", "/Image/Icon/40.png", "/Image/Icon/41.png", "/Image/Icon/42.png", "聲  望");
tc.AddItem(63, 28, 1, "/Image/Icon/39.png", "/Image/Icon/40.png", "/Image/Icon/41.png", "/Image/Icon/42.png", "稱  號");
tc.AddItem(63, 28, 1, "/Image/Icon/39.png", "/Image/Icon/40.png", "/Image/Icon/41.png", "/Image/Icon/42.png", "榮  譽");
……
tc.SelectionChanged += (sender, item) => {
 QXTabControl tabControl = sender as QXTabControl;
 switch (item.Text) {
  case "屬  性":
    tabControl.SetBody(leaderAttributePart);
  break;
  case "聲  望":
    tabControl.SetBody(new Canvas() {
    Background = new ImageBrush() { ImageSource = Super.GetImage("/Image/Plate/RoleAttributeBack1.png") },
    Width = 350,
    Height = 389,
    });
  break;
  case "稱  號":
    tabControl.SetBody(new Canvas() {
                       Background = new ImageBrush() { ImageSource = Super.GetImage("/Image/Plate/RoleAttributeBack2.png") },
     Width = 350,
     Height = 389,
    });
  break;
  default:
     tabControl.SetBody(null);
  break;
 };
};

運行時效果:

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved