private void uiTool_Click(object sender, Janus.Windows.UI.CommandBars.CommandEventArgs e) { NBGIS.PluginEngine.ITool tool = this.m_ToolCol[e.Command.Key]; //Tool第一次按下 if (this.m_Application.CurrentTool == null && this.m_MapControl.CurrentTool == null && this.m_PageLayoutControl.CurrentTool == null) { this.StatusBar.Panels[0].Text = tool.Message; Janus.Windows.UI.CommandBars.UICommand cmd = (Janus.Windows.UI.CommandBars.UICommand)sender; cmd.Checked = Janus.Windows.UI.InheritableBoolean.True; this.axMapControl.MousePointer = (ESRI.ArcGIS.Controls.esriControlsMousePointer)(tool.Cursor); this.axPageLayoutControl.MousePointer = (ESRI.ArcGIS.Controls.esriControlsMousePointer)(tool.Cursor); tool.OnClick(); this.m_Application.CurrentTool = tool.ToString(); } else { if (this.m_Application.CurrentTool == e.Command.Key) { //如果是连续第二次按下,则这个Tool完成操作后处于关闭状态 Janus.Windows.UI.CommandBars.UICommand cmd = (Janus.Windows.UI.CommandBars.UICommand)sender; cmd.Checked = Janus.Windows.UI.InheritableBoolean.False; this.axMapControl.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault; this.axPageLayoutControl.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault; this.m_Application.CurrentTool = null; this.m_Application.MapControl.CurrentTool = null; this.m_Application.PageLayoutControl.CurrentTool = null; } else { //按下一个Tool后没有关闭接着按另一个Tool,则关闭前一个Tool Janus.Windows.UI.CommandBars.UICommand lastTool = this.uiCommandManager.Commands[this.m_Application.CurrentTool]; if (lastTool != null) { lastTool.Checked = Janus.Windows.UI.InheritableBoolean.False; } this.m_Application.MapControl.CurrentTool = null; this.m_Application.PageLayoutControl.CurrentTool = null; //设置后一个Tool的状态 this.StatusBar.Panels[0].Text = tool.Message; Janus.Windows.UI.CommandBars.UICommand cmd = (Janus.Windows.UI.CommandBars.UICommand)sender; cmd.Checked = Janus.Windows.UI.InheritableBoolean.True; this.axMapControl.MousePointer = (ESRI.ArcGIS.Controls.esriControlsMousePointer)(tool.Cursor); this.axPageLayoutControl.MousePointer = (ESRI.ArcGIS.Controls.esriControlsMousePointer)(tool.Cursor); tool.OnClick(); this.m_Application.CurrentTool = tool.ToString(); } } }
private void CreateUICommandAndTool(Dictionary <string, NBGIS.PluginEngine.ICommand> Cmds, Dictionary <string, NBGIS.PluginEngine.ITool> Tools) { //遍历ICommand对象集合 foreach (KeyValuePair <string, NBGIS.PluginEngine.ICommand> cmd in Cmds) { //获得一个ICommand对象 NBGIS.PluginEngine.ICommand nbCmd = cmd.Value; //产生一个UICommand对象 Janus.Windows.UI.CommandBars.UICommand uiCmd = new Janus.Windows.UI.CommandBars.UICommand(); //根据ICommand的信息设置UICommand的属性 uiCmd.ToolTipText = nbCmd.Tooltip; uiCmd.CategoryName = nbCmd.Category; uiCmd.Text = nbCmd.Caption; uiCmd.Image = nbCmd.Bitmap; uiCmd.Key = nbCmd.ToString(); //UICommand的Enabled属性默认为true if (!nbCmd.Enabled) { uiCmd.Enabled = Janus.Windows.UI.InheritableBoolean.False; } //UICommand的Checked属性默认为false if (nbCmd.Checked) { uiCmd.Checked = Janus.Windows.UI.InheritableBoolean.True; } //产生UICommand时调用OnCreate方法,将主框架对象传递给插件对象 nbCmd.OnCreate(this.m_Application); //使用委托机制处理Command的事件 //所有的UICommand对象的Click事件均使用this.Command_Click方法处理 uiCmd.Click += new Janus.Windows.UI.CommandBars.CommandEventHandler(uiCmd_Click); //将生成的UICommand添加到CommandManager中 this.uiCommandManager.Commands.Add(uiCmd); } //遍历ITool对象集合 foreach (KeyValuePair <string, NBGIS.PluginEngine.ITool> tool in Tools) { NBGIS.PluginEngine.ITool nbTool = tool.Value; Janus.Windows.UI.CommandBars.UICommand uiTool = new Janus.Windows.UI.CommandBars.UICommand(); uiTool.CategoryName = nbTool.Category; uiTool.Text = nbTool.Caption; uiTool.ToolTipText = nbTool.Tooltip; uiTool.Image = nbTool.Bitmap; uiTool.Key = nbTool.ToString(); if (!nbTool.Enabled) { uiTool.Enabled = Janus.Windows.UI.InheritableBoolean.False; } if (nbTool.Checked) { uiTool.Checked = Janus.Windows.UI.InheritableBoolean.True; } nbTool.OnCreate(this.m_Application); uiTool.Click += new Janus.Windows.UI.CommandBars.CommandEventHandler(uiTool_Click); this.uiCommandManager.Commands.Add(uiTool); } }
/// <summary> /// 创建UI层的菜单栏 /// </summary> /// <param name="Menus"></param> private void CreateMenus(Dictionary <string, NBGIS.PluginEngine.IMenuDef> Menus) { //遍历Menu集合中的元素 foreach (KeyValuePair <string, NBGIS.PluginEngine.IMenuDef> menu in Menus) { NBGIS.PluginEngine.IMenuDef nbMenu = menu.Value; //新建菜单对象 ToolStripMenuItem UIMenu = new ToolStripMenuItem(); //设置菜单属性 UIMenu.Text = nbMenu.Caption; UIMenu.Tag = nbMenu; UIMenu.AccessibleName = nbMenu.ToString(); //将Menu添加MainMenu的Commands中 MainMenu.Items.Add(UIMenu); //将Command和Tool插入到menu中 //遍历每一个菜单item NBGIS.PluginEngine.ItemDef itemDef = new NBGIS.PluginEngine.ItemDef(); for (int i = 0; i < nbMenu.ItemCount; i++) { //寻找该菜单对象的信息,如该菜单上的Item数量,是否为Group nbMenu.GetItemInfo(i, itemDef); NBGIS.PluginEngine.ITool nbtool = m_DicPlugins[itemDef.ID] as NBGIS.PluginEngine.ITool; if (nbtool != null) { //产生一个ITool对象 ToolStripMenuItem UITool = new ToolStripMenuItem(); //根据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) { UIMenu.DropDownItems.Add(new ToolStripSeparator()); } UIMenu.DropDownItems.Add(UITool); } NBGIS.PluginEngine.ICommand nbcmd = m_DicPlugins[itemDef.ID] as NBGIS.PluginEngine.ICommand; if (nbcmd != null) { //产生一个UICommand对象 ToolStripMenuItem UICommand = new ToolStripMenuItem(); //根据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()); } UIMenu.DropDownItems.Add(UICommand); } } } }
void UITool_Click(object sender, EventArgs e) { //获得当前点击的ITool对象 ToolStripButton pTempBtn = sender as ToolStripButton; ToolStripMenuItem pTempMenuItem = sender as ToolStripMenuItem; ToolStripItem pItem = pTempBtn; if (null == pTempBtn) { pItem = pTempMenuItem; } if (null == pItem) { return; } string strKey = pItem.AccessibleName; NBGIS.PluginEngine.ITool tool = this._ToolCol[strKey]; //第一次按下 if (_App.CurrentTool == null && _mapControl.CurrentTool == null && _pageLayoutControl.CurrentTool == null) { toolStripStatusLabel1.Text = tool.Message; if (null != pTempBtn) { pTempBtn.Checked = true; } axMapControl.MousePointer = (ESRI.ArcGIS.Controls.esriControlsMousePointer)(tool.Cursor); axPageLayoutControl.MousePointer = (ESRI.ArcGIS.Controls.esriControlsMousePointer)(tool.Cursor); tool.OnClick(); _App.CurrentTool = tool.ToString(); } else { if (_App.CurrentTool == strKey) { //如果是连续二次按下,则使这个Tool完成操作后处于关闭状态 if (null != pTempBtn) { pTempBtn.Checked = false; } axMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault; axPageLayoutControl.MousePointer = esriControlsMousePointer.esriPointerDefault; _App.CurrentTool = null; _App.MapControl.CurrentTool = null; _App.PageLayoutControl.CurrentTool = null; } else { ////按下一个Tool后没有关闭接着去按另一个Tool,则关闭前一个Tool ////获得前一个Tool if (null != pTempBtn) { ToolStripItem pItem1 = GetCurBtn(pItem.GetCurrentParent(), _App.CurrentTool); if (null == pItem1) { return; } ToolStripButton lastTool = pItem1 as ToolStripButton; if (lastTool != null) { lastTool.Checked = false; } _App.PageLayoutControl.CurrentTool = null; _App.MapControl.CurrentTool = null; } //设置后一个Tool的状态 toolStripStatusLabel1.Text = tool.Message; if (null != pTempBtn) { pTempBtn.Checked = false; } axMapControl.MousePointer = (ESRI.ArcGIS.Controls.esriControlsMousePointer)(tool.Cursor); axPageLayoutControl.MousePointer = (ESRI.ArcGIS.Controls.esriControlsMousePointer)(tool.Cursor); tool.OnClick(); _App.CurrentTool = tool.ToString(); } } }
/// <summary> /// 创建ToolBar的UI层对象 /// </summary> /// <param name="toolBars"></param> private void CreateToolBars(Dictionary <string, NBGIS.PluginEngine.IToolBarDef> toolBars) { foreach (KeyValuePair <string, NBGIS.PluginEngine.IToolBarDef> toolbar in toolBars) { NBGIS.PluginEngine.IToolBarDef nbtoolbar = toolbar.Value; //产生UICommandBar对象 ToolStrip UIToolbar = new ToolStrip(); //设置UICommandBar的属性 //UIToolbar.CommandManager = this.uiCommandManager; UIToolbar.Name = nbtoolbar.Name; UIToolbar.Text = nbtoolbar.Caption; UIToolbar.Tag = nbtoolbar; UIToolbar.AccessibleName = nbtoolbar.ToString(); //将Command和Tool插入到ToolBar中 NBGIS.PluginEngine.ItemDef itemDef = new ItemDef(); for (int i = 0; i < nbtoolbar.ItemCount; i++) { nbtoolbar.GetItemInfo(i, itemDef); NBGIS.PluginEngine.ICommand nbcmd = m_DicPlugins[itemDef.ID] as NBGIS.PluginEngine.ICommand; if (nbcmd != null) { //产生一个UICommand对象 ToolStripButton UICommand = new ToolStripButton(); UICommand.DisplayStyle = ToolStripItemDisplayStyle.Image; //根据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.Items.Add(new ToolStripSeparator()); } UIToolbar.Items.Add(UICommand); } //获得一个ITool对象 NBGIS.PluginEngine.ITool nbtool = m_DicPlugins[itemDef.ID] as NBGIS.PluginEngine.ITool; if (nbtool != null) { //产生一个ITool对象 ToolStripButton UITool = new ToolStripButton(); 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.Items.Add(UITool); } } UIToolbar.Dock = DockStyle.Top; this.toolStripContainer1.TopToolStripPanel.Controls.Add(UIToolbar); } }