ZedGraph右键菜单怎样禁止它弹出(转)

private void ZGC_ContextMenuBuilder( ZedGraphControl sender,
                     ContextMenuStrip menuStrip, Point mousePt,
                     ZedGraphControl.ContextMenuObjectState objState )
        {
            try
            {
                #region //去掉不用的键

                //去掉其他菜单选项可以把set_default改为对应的字符串。
                //title_def         标题
                //copy              复制
                //copied_to_clip    复制到剪贴板
                //page_setup        页面设置...
                //print             打印...
                //save_as           另存图表...
                //set_default       恢复默认大小
                //show_val          显示节点数值
               
                //unzoom            还原缩放
                //unpan             还原移动
                //undo_all          还原缩放/移动
               
                //x_title_def       X 轴
                //y_title_def       Y 轴
                      
                //每个循环只能遍历一个键
                foreach( ToolStripMenuItem item in menuStrip.Items )
                {
                    if( ( string )item.Tag == "set_default" )                // “恢复默认大小”菜单项
                    {
                        menuStrip.Items.Remove( item );//移除菜单项
                        item.Visible = false; //不显示
                        break;
                    }
                }
                foreach( ToolStripMenuItem item in menuStrip.Items )
                {
                    if( ( string )item.Tag == "copy" )                // “复制”菜单项
                    {
                        menuStrip.Items.Remove( item );//移除菜单项
                        item.Visible = false; //不显示
                        break;
                    }
                }
                foreach( ToolStripMenuItem item in menuStrip.Items )
                {
                    if( ( string )item.Tag == "page_setup" )                // “页面设置”菜单项
                    {
                        menuStrip.Items.Remove( item );//移除菜单项
                        item.Visible = false; //不显示
                        break;
                    }
                }
                foreach( ToolStripMenuItem item in menuStrip.Items )
                {
                    if( ( string )item.Tag == "print" )                // “打印”菜单项
                    {
                        menuStrip.Items.Remove( item );//移除菜单项
                        item.Visible = false; //不显示
                        break;
                    }
                }
                foreach( ToolStripMenuItem item in menuStrip.Items )
                {
                    if( ( string )item.Tag == "save_as" )                // “另存为”菜单项
                    {
                        menuStrip.Items.Remove( item );//移除菜单项
                        item.Visible = false; //不显示
                        break;
                    }
                }
                #endregion
            }
            catch( System.Exception ex )
            {
                MessageBox.Show( "Error Code: 112,初始化右键菜单错误" + ex.ToString( ) );
            }
        }
        #endregion

//**如果完全不需要显示的话,就用 zedCntrol.IsShowContextMenu = false;

posted on 2015-01-09 13:44  xihong  阅读(591)  评论(0编辑  收藏  举报

导航