コード例 #1
0
        void UICommand_Click(object sender, EventArgs e)
        {
            //ToolStripButton pTempBtn = sender as ToolStripButton;
            ButtonItem pTemp = sender as ButtonItem;
            //ToolStripMenuItem pTempMenuItem = sender as ToolStripMenuItem;
            //ToolStripItem pItem = pTempBtn;
            //if (null == pTempBtn)
            //{
            //    pItem = pTempMenuItem;
            //}
            //if (null == pItem)
            //{
            //    return;
            //}
            string strKey = pTemp.AccessibleName;

            //当前Command被按下时,CurrentTool设置为null
            //MapControl和PageLayoutControl的也设置为null
            _App.CurrentTool                   = null;
            _App.MapControl.CurrentTool        = null;
            _App.PageLayoutControl.CurrentTool = null;
            //一切在Command被按下前未完成的Tool操作都可能使Tool的Checked为true
            //此项必须设置为False
            //遍历所有的Command,设置每一个Command的选择状态为False
            ToolStripButton UICmd = null;

            //foreach (var item in pItem.GetCurrentParent().Items)
            //{
            //    UICmd = item as ToolStripButton;
            //    if (null == UICmd)
            //        continue;
            //    UICmd.Checked = false;
            //}


            MyPluginEngine.ICommand cmd = _CommandCol[strKey];
            ////在状态栏显示插件信息
            this.statusButton1.Text = "当前操作:" + cmd.Message;
            if (null != pTemp)
            {
                pTemp.Checked = true;
            }
            //((ToolStripButton)sender).Checked = true;
            //设置Map控件的鼠标
            axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
            cmd.OnClick();
            //((ToolStripButton)sender).Checked = false;
            if (null != pTemp)
            {
                pTemp.Checked = false;
            }
        }
コード例 #2
0
ファイル: MainGIS.cs プロジェクト: hahahuahai/MyPluginEngine
        void UICommand_Click(object sender, EventArgs e)
        {
            ButtonItem pTemp  = sender as ButtonItem;
            string     strKey = pTemp.AccessibleName;

            //当前Command被按下时,CurrentTool设置为null
            if (_App.CurrentTool != null)
            {
                MyPluginEngine.ITool lastTool = _ToolCol[_App.CurrentTool];
                //先判断上一个Tool是不是工具栏中的
                ButtonItem lastItem = GetButtonItemFromTools(lastTool.Caption);
                if (lastItem != null)
                {
                    lastItem.Checked = false;
                }
                else    //若不是工具栏中的,则判断是不是菜单栏中得到Tool
                {
                    lastItem = GetButtonItemFromMenus(lastTool.Caption);
                    if (lastItem != null)
                    {
                        lastItem.Checked = false;
                    }
                }
                _App.CurrentTool = null;
            }
            _App.MapControl.CurrentTool        = null;
            _App.PageLayoutControl.CurrentTool = null;

            ToolStripButton UICmd = null;

            MyPluginEngine.ICommand cmd = _CommandCol[strKey];
            ////在状态栏显示插件信息
            this.statusButton1.Text = "当前操作:" + cmd.Message;
            if (null != pTemp)
            {
                pTemp.Checked = true;
            }
            //设置Map控件的鼠标
            axMapControl1.MousePointer        = esriControlsMousePointer.esriPointerDefault;
            axPageLayoutControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
            cmd.OnClick();
            if (null != pTemp)
            {
                pTemp.Checked = false;
            }
        }
コード例 #3
0
ファイル: MainGIS.cs プロジェクト: hahahuahai/MyPluginEngine
        /// <summary>
        /// 创建UI层的菜单栏 使用ribbonControl实现菜单栏的功能
        /// </summary>
        /// <param name="Menus"></param>
        private void CreateMenus(Dictionary <string, MyPluginEngine.IMenuDef> Menus)
        {
            //遍历Menu集合中的元素
            foreach (KeyValuePair <string, MyPluginEngine.IMenuDef> menu in Menus)
            {
                MyPluginEngine.IMenuDef nbMenu = menu.Value;
                //新建菜单对象
                //ToolStripMenuItem UIMenu = new ToolStripMenuItem();
                RibbonTabItem UIMenu = new RibbonTabItem();
                //设置菜单属性
                UIMenu.Text           = nbMenu.Caption;
                UIMenu.Tag            = nbMenu;
                UIMenu.AccessibleName = nbMenu.ToString();

                //添加ribbonpanel
                RibbonPanel MenuPanel = new RibbonPanel();
                MenuPanel.Text = nbMenu.Caption;
                MenuPanel.Dock = DockStyle.Fill;
                MenuPanel.Font = new System.Drawing.Font("微软雅黑", 9F);
                UIMenu.Panel   = MenuPanel;

                // 添加 ribbonbar
                RibbonBar MenuBar = new RibbonBar();
                //MenuBar.Text = nbMenu.Caption;//分组标题
                //MenuBar.Dock = DockStyle.Fill;

                //将Menu添加MainMenu的Commands中
                //MainMenu.Items.Add(UIMenu);
                //将Command和Tool插入到menu中
                //遍历每一个菜单item
                MyPluginEngine.ItemDef itemDef = new MyPluginEngine.ItemDef();
                for (int i = 0; i < nbMenu.ItemCount; i++)
                {
                    //寻找该菜单对象的信息,如该菜单上的Item数量,是否为Group
                    nbMenu.GetItemInfo(i, itemDef);

                    MyPluginEngine.ITool nbtool = m_DicPlugins[itemDef.ID] as MyPluginEngine.ITool;
                    if (nbtool != null)
                    {
                        //产生一个ITool对象
                        //ToolStripMenuItem UITool = new ToolStripMenuItem();
                        //
                        ButtonItem UITool = new ButtonItem();
                        //根据ITool的信息设置UITool的属性
                        //UITool.ToolTipText = nbtool.Tooltip;
                        UITool.ImagePosition  = DevComponents.DotNetBar.eImagePosition.Top;
                        UITool.Text           = nbtool.Caption;
                        UITool.Image          = nbtool.Bitmap;
                        UITool.AccessibleName = nbtool.ToString();
                        //UITool.Key = nbtool.ToString();
                        UITool.Enabled = nbtool.Enabled;
                        UITool.Checked = nbtool.Checked;
                        //产生UICommand是调用OnCreate方法,将主框架对象传递给插件对象
                        nbtool.OnCreate(this._App);
                        //使用委托机制处理Command的事件
                        //所有的UICommand对象Click事件均使用this.UITool_Click方法处理
                        UITool.Click += new EventHandler(UITool_Click);
                        //将生成的UICommand添加到CommandManager中

                        //MenuBar.Text = nbtool.Category;
                        if (itemDef.Group)
                        {
                            MenuBar      = new RibbonBar();
                            MenuBar.Text = nbtool.Category;//分组标题
                            //UIMenu.DropDownItems.Add(new ToolStripSeparator());
                        }
                        MenuBar.Items.Add(UITool);
                        //UIMenu.SubItems.Add(UITool);
                    }
                    MyPluginEngine.ICommand nbcmd = m_DicPlugins[itemDef.ID] as MyPluginEngine.ICommand;
                    if (nbcmd != null)
                    {
                        //产生一个UICommand对象
                        //ToolStripMenuItem UICommand = new ToolStripMenuItem();
                        //
                        ButtonItem UICommand = new ButtonItem();
                        UICommand.ImagePosition = DevComponents.DotNetBar.eImagePosition.Top;
                        //根据ICommand的信息设置UICommand的属性
                        //UICommand.ToolTipText = nbcmd.Tooltip;
                        UICommand.Text           = nbcmd.Caption;
                        UICommand.Image          = nbcmd.Bitmap;
                        UICommand.AccessibleName = nbcmd.ToString();
                        UICommand.Enabled        = nbcmd.Enabled;
                        //UICommand的Checked与command的属性一致
                        UICommand.Checked = nbcmd.Checked;
                        //产生UICommand是调用OnCreate方法,将主框架对象传递给插件对象
                        nbcmd.OnCreate(this._App);
                        //使用委托机制处理Command的事件
                        //所有的UICommand对象Click事件均使用this.Command_Click方法处理
                        UICommand.Click += new EventHandler(UICommand_Click);
                        //将生成的UICommand添加到CommandManager中
                        //如果分组,则在该UI对象前加上一个分隔符
                        if (itemDef.Group)
                        {
                            //UIMenu.DropDownItems.Add(new ToolStripSeparator());
                            MenuBar      = new RibbonBar();
                            MenuBar.Text = UICommand.Category;
                        }
                        //UIMenu.DropDownItems.Add(UICommand);
                        MenuBar.Items.Add(UICommand);
                    }
                    MenuPanel.Controls.Add(MenuBar);
                }

                this.MainMenu.Controls.Add(MenuPanel);
                this.MainMenu.Items.Add(UIMenu);
                this.MainMenu.SelectFirstVisibleRibbonTab();
            }
        }
コード例 #4
0
ファイル: MainGIS.cs プロジェクト: hahahuahai/MyPluginEngine
        /// <summary>
        /// 创建ToolBar的UI层对象
        /// </summary>
        /// <param name="toolBars"></param>
        private void CreateToolBars(Dictionary <string, MyPluginEngine.IToolBarDef> toolBars)
        {
            foreach (KeyValuePair <string, MyPluginEngine.IToolBarDef> toolbar in toolBars)
            {
                MyPluginEngine.IToolBarDef nbtoolbar = toolbar.Value;
                //产生UICommandBar对象
                //ToolStrip UIToolbar = new ToolStrip();
                RibbonPanel UIToolPanel = new RibbonPanel();
                //设置UICommandBar的属性
                //UIToolbar.CommandManager = this.uiCommandManager;
                UIToolPanel.Name = nbtoolbar.Name;
                //UIToolPanel.Text = nbtoolbar.Caption;
                UIToolPanel.Tag            = nbtoolbar;
                UIToolPanel.AccessibleName = nbtoolbar.ToString();
                UIToolPanel.Dock           = DockStyle.Fill;

                RibbonBar UIToolBar = new RibbonBar();
                //UIToolBar.Text = nbtoolbar.Caption;

                //将Command和Tool插入到ToolBar中
                MyPluginEngine.ItemDef itemDef = new ItemDef();
                for (int i = 0; i < nbtoolbar.ItemCount; i++)
                {
                    nbtoolbar.GetItemInfo(i, itemDef);
                    MyPluginEngine.ICommand nbcmd = null;
                    //防止ICommond类或ITool类的ID与工具栏集合中项的ID无法对应上而发生异常
                    try
                    {
                        nbcmd = m_DicPlugins[itemDef.ID] as MyPluginEngine.ICommand;
                    }
                    catch (System.Exception ex)
                    {
                        nbcmd = null;
                    }

                    if (nbcmd != null)
                    {
                        //产生一个UICommand对象
                        //ToolStripButton UICommand = new ToolStripButton();
                        ButtonItem UICommand = new ButtonItem();
                        //UICommand.sty = ;
                        //根据ICommand的信息设置UICommand的属性
                        //UICommand.ToolTipText = nbcmd.Tooltip;
                        UICommand.Text           = nbcmd.Caption;
                        UICommand.Image          = nbcmd.Bitmap;
                        UICommand.AccessibleName = nbcmd.ToString();
                        UICommand.Enabled        = nbcmd.Enabled;
                        //UICommand的Checked与command的属性一致
                        UICommand.Checked = nbcmd.Checked;
                        //产生UICommand是调用OnCreate方法,将主框架对象传递给插件对象
                        nbcmd.OnCreate(this._App);
                        //使用委托机制处理Command的事件
                        //所有的UICommand对象Click事件均使用this.Command_Click方法处理
                        UICommand.Click += new EventHandler(UICommand_Click);
                        //将生成的UICommand添加到CommandManager中
                        //如果分组,则在该UI对象前加上一个分隔符
                        if (itemDef.Group)
                        {
                            UIToolBar = new RibbonBar();
                            //UIToolBar.Text = nbtoolbar.Caption;
                        }
                        UIToolBar.Items.Add(UICommand);
                    }

                    //获得一个ITool对象
                    MyPluginEngine.ITool nbtool = m_DicPlugins[itemDef.ID] as MyPluginEngine.ITool;
                    if (nbtool != null)
                    {
                        //产生一个ITool对象
                        //ToolStripButton UITool = new ToolStripButton();
                        ButtonItem UITool = new ButtonItem();
                        //UITool.DisplayStyle = ToolStripItemDisplayStyle.Image;
                        //根据ITool的信息设置UITool的属性
                        //UITool.ToolTipText = nbtool.Tooltip;
                        UITool.Text           = nbtool.Caption;
                        UITool.Image          = nbtool.Bitmap;
                        UITool.AccessibleName = nbtool.ToString();
                        //UITool.Key = nbtool.ToString();
                        UITool.Enabled = nbtool.Enabled;
                        UITool.Checked = nbtool.Checked;
                        //产生UICommand是调用OnCreate方法,将主框架对象传递给插件对象
                        nbtool.OnCreate(this._App);
                        //使用委托机制处理Command的事件
                        //所有的UICommand对象Click事件均使用this.UITool_Click方法处理
                        UITool.Click += new EventHandler(UITool_Click);
                        //将生成的UICommand添加到CommandManager中
                        if (itemDef.Group)
                        {
                            //UIToolbar.Items.Add(new ToolStripSeparator());
                            UIToolBar = new RibbonBar();
                            //UIToolBar.Text = nbtoolbar.Caption;
                            //UIToolBar.Items.Add();
                        }
                        UIToolBar.Items.Add(UITool);
                    }
                    UIToolPanel.Controls.Add(UIToolBar);
                }

                this.MainTool.Controls.Add(UIToolPanel);
            }
        }