Smobiler APP開發----ToolBar和TabPageView組合使用


  今天就學習一下如何通過ToolBar和TabPageView組合使用實現通過點擊標題欄實現界面轉換。

  官方給ToolBar一個事件回調:

 

 

 

 官方給TabPageView一個回調事件:

  

 

 

     由於是我們通過點擊ToolBar標題欄實現頁面轉換,所以這里我們只需要給ToolBar添加ToolBarItemClick事件即可。而TabPageView可以不用添加PageIndexChanged的事件,我們可以通過改變ToolBar的標題欄來動態改變TabPageView的頁數。

  ToolBar添加ToolBarItemClick事件:

 

代碼:

 this.toolBar1.ToolbarItemClick += new Smobiler.Core.Controls.ToolbarItemClickEventHandler(this.toolBar_ToolbarItemClick);

 

 回調方法:

 

 

 代碼:

 private void toolBar_ToolbarItemClick(object sender, ToolbarClickEventArgs e)
        {
            if (toolBar1.SelectedIndex != tabPageView1.PageIndex)
            {
                switch (e.Name)
                {
                    case "首頁":
                        tabPageView1.PageIndex = 0;
                        break;
                    case "財務":
                        tabPageView1.PageIndex = 1;
                        break;
                    case "審批":
                         tabPageView1.PageIndex = 2;
                        break;
                    case "我的":
                         tabPageView1.PageIndex = 3;
                        break;                  
                }
            }
        }

新建4個頁面:

 

 動態給TabPageView添加頁數:

  加載所有組件后,首先要添加頁面:

  

 

 代碼:

this.Load += new System.EventHandler(this.SmobilerMain_Load);

回調方法:

 private void SmobilerMain_Load(object sender, EventArgs e)
        {
            Demo.Demo1Control demo1 = new Demo.Demo1Control() { Dock = System.Windows.Forms.DockStyle.Fill }; 
            tabPageView1.Controls.Add(demo1);
            Demo.Demo2Control demo2 = new Demo.Demo2Control() { Dock = System.Windows.Forms.DockStyle.Fill }; 
            tabPageView1.Controls.Add(demo2);

            Demo.Demo3Control demo3 = new Demo.Demo3Control() { Dock = System.Windows.Forms.DockStyle.Fill }; 
            tabPageView1.Controls.Add(demo3);
            Demo.Demo4Control demo4 = new Demo.Demo4Control() { Dock = System.Windows.Forms.DockStyle.Fill }; 
            tabPageView1.Controls.Add(demo4);
           
            toolBar1.SelectedIndex = 0;
        }

運行,看實現效果:

 

這里菜單欄已經做完了。下一篇就說一下下拉框如何使用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM