Devexpress PdfViewer汉化及隐藏右键菜单

先看效果图

1.效果图 隐藏了打印与文档属性功能
效果图

2.原图
原图

1.关键事件 PopupMenuShowing

   public From()
       { 
           InitializeComponent();
           //弹出菜单加载事件
           pdfViewer1.PopupMenuShowing += PdfViewer1_PopupMenuShowing; 

       }


2.关键代码

通过 Visible属性 隐藏菜单项; Caption属性汉化

       //代码可以直接使用
       /// <summary>
       /// 汉化菜单
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>
       private void PdfViewer1_PopupMenuShowing(object sender, DevExpress.XtraPdfViewer.PdfPopupMenuShowingEventArgs e)
       {
           PopupMenu menu = e.Menu;
           foreach (var item in menu.ItemLinks.ToList())
           {
               switch (item.Caption)
               {
                   case "Select Tool":
                       item.Caption = "指针";
                       break;
                   case "Hand Tool":
                       item.Caption = "移动";
                       break;
                   case "Previous View":
                       item.Caption = "上一页";
                       break;
                   case "Next View":
                       item.Caption = "下一页";
                       break;
                   case "Rotate Clockwise":
                       item.Caption = "顺时针旋转";
                       break;
                   case "Rotate Counterclockwise":
                       item.Caption = "逆时针旋转";
                       break;
                   case "Print...":
                       item.Caption = "打印";
                       item.Visible = false;
                       break;
                   case "Find":
                       item.Caption = "搜索";
                       break;
                   case "Select All":
                       item.Caption = "全选";
                       break;
                   case "Document properties...":
                       item.Caption = "文档属性";
                       item.Visible = false;
                       break;
                   // ... 添加其他菜单项的汉化
                   default:
                       continue;
               }
           }
       }

posted @ 2024-04-19 16:57  我本梁人  阅读(148)  评论(0编辑  收藏  举报