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;
        }

运行,看实现效果:

这里菜单栏已经做完了。下一篇就说一下下拉框如何使用。

原文地址:https://www.cnblogs.com/zpy1993-09/p/13957172.html