소스 검색

添加右键功能

章政 7 년 전
부모
커밋
0c24fa14d7
5개의 변경된 파일59개의 추가작업 그리고 14개의 파일을 삭제
  1. 2 1
      UAS_Web/Browser.cs
  2. 3 0
      UAS_Web/UAS_Web.csproj
  3. 5 5
      UAS_Web/app.config
  4. 43 0
      UAS_Web/tool/CustomCommand.cs
  5. 6 8
      UAS_Web/tool/MenuHandler.cs

+ 2 - 1
UAS_Web/Browser.cs

@@ -18,11 +18,12 @@ namespace UAS_Web
         {
             InitializeComponent();
             Text = "思拓微-供应商条码打印";
-            string path = "http://192.168.253.80:8090/ERP/jsps/vendbarcode/login.jsp";
+            string path = "http://stwecig.vicp.io:8099/ERP/jsps/vendbarcode/login.jsp";
             webBrowser = new ChromiumWebBrowser(path)
             {
                 Dock = DockStyle.Fill
             };
+            CheckForIllegalCrossThreadCalls = false;
             webBrowser.MenuHandler = new MenuHandler();
             webBrowser.RequestHandler = new RequestHandler();
             webBrowser.DownloadHandler = new DownLoadFile();

+ 3 - 0
UAS_Web/UAS_Web.csproj

@@ -15,6 +15,7 @@
     <FileAlignment>512</FileAlignment>
     <NuGetPackageImportStamp>
     </NuGetPackageImportStamp>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <PlatformTarget>x86</PlatformTarget>
@@ -84,6 +85,7 @@
       <HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net40\Newtonsoft.Json.dll</HintPath>
       <Private>True</Private>
     </Reference>
+    <Reference Include="PresentationCore" />
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
@@ -110,6 +112,7 @@
     </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="tool\CustomCommand.cs" />
     <Compile Include="tool\DownLoadFile.cs" />
     <Compile Include="tool\FilterManager.cs" />
     <Compile Include="tool\MenuHandler.cs" />

+ 5 - 5
UAS_Web/app.config

@@ -1,15 +1,15 @@
-<?xml version="1.0" encoding="utf-8" ?>
+<?xml version="1.0" encoding="utf-8"?>
 <configuration>
     <configSections>
-        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
-            <section name="UAS_Web.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
+        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+            <section name="UAS_Web.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
         </sectionGroup>
     </configSections>
     <userSettings>
         <UAS_Web.Properties.Settings>
             <setting name="PrinterName" serializeAs="String">
-                <value />
+                <value/>
             </setting>
         </UAS_Web.Properties.Settings>
     </userSettings>
-</configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

+ 43 - 0
UAS_Web/tool/CustomCommand.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows.Input;
+
+namespace UAS_Web.tool
+{
+    class CustomCommand : ICommand
+    {
+        Action _TargetExecuteMethod;
+        Func<bool> _TargetCanExecuteMethod;
+        public event EventHandler CanExecuteChanged = delegate { };
+
+        public CustomCommand(Action executeMethod)
+        {
+            _TargetExecuteMethod = executeMethod;
+        }
+
+        bool ICommand.CanExecute(object parameter)
+        {
+            if (_TargetCanExecuteMethod != null)
+            {
+                return _TargetCanExecuteMethod();
+            }
+            if (_TargetExecuteMethod != null)
+            {
+                return true;
+            }
+            return false;
+        }
+
+        public void RaiseCanExecuteChanged()
+        {
+            CanExecuteChanged(this, EventArgs.Empty);
+        }
+
+        void ICommand.Execute(object parameter)
+        {
+            _TargetExecuteMethod?.Invoke();
+        }
+    }
+}

+ 6 - 8
UAS_Web/tool/MenuHandler.cs

@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using CefSharp;
+using CefSharp;
 
 namespace UAS_Web.tool
 {
@@ -10,8 +6,10 @@ namespace UAS_Web.tool
     {
         public void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
         {
-            //browser.ShowDevTools();
             model.Clear();
+            model.AddItem(CefMenuCommand.Copy, "复制");
+            model.AddItem(CefMenuCommand.Paste, "粘贴");
+            model.AddItem(CefMenuCommand.Reload, "重新加载");
         }
 
         public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
@@ -21,7 +19,7 @@ namespace UAS_Web.tool
 
         public void OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame)
         {
-            //throw new NotImplementedException();
+
         }
 
         public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
@@ -29,4 +27,4 @@ namespace UAS_Web.tool
             return false;
         }
     }
-}
+}