CrazyIter_Bin 1 年之前
父節點
當前提交
ddb6044d68

+ 10 - 10
HTEXTeach/MainRibbon.cs

@@ -55,18 +55,18 @@ namespace HTEXTeach
         }
         private void button1_Click(object sender, RibbonControlEventArgs e)
         {
-            if (IsEditingMode())
-            {
-                MessageBox.Show("编辑模式");
+            //if (IsEditingMode())
+            //{
+            //    MessageBox.Show("编辑模式");
 
-            }
-            else { MessageBox.Show("不是编辑模式"); }
-            if (IsSlideShowInProgress())
-            {
-                MessageBox.Show("全屏");
+            //}
+            //else { MessageBox.Show("不是编辑模式"); }
+            //if (IsSlideShowInProgress())
+            //{
+            //    MessageBox.Show("全屏");
 
-            }
-            else { MessageBox.Show("不是全屏"); }
+            //}
+            //else { MessageBox.Show("不是全屏"); }
 
             Microsoft.Office.Interop.PowerPoint.Presentation presentation = Globals.ThisAddIn.Application.ActivePresentation;
             // 在演示文稿中添加新的幻灯片

+ 19 - 7
HTEXTeachLib/HTEXTeachLib.csproj

@@ -13,6 +13,8 @@
     <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
     <WarningLevel>4</WarningLevel>
     <Deterministic>true</Deterministic>
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -32,6 +34,15 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.2277.86, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
+      <HintPath>F:\NuGet\packages\Microsoft.Web.WebView2.1.0.2277.86\lib\net45\Microsoft.Web.WebView2.Core.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Web.WebView2.WinForms, Version=1.0.2277.86, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
+      <HintPath>F:\NuGet\packages\Microsoft.Web.WebView2.1.0.2277.86\lib\net45\Microsoft.Web.WebView2.WinForms.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Web.WebView2.Wpf, Version=1.0.2277.86, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
+      <HintPath>F:\NuGet\packages\Microsoft.Web.WebView2.1.0.2277.86\lib\net45\Microsoft.Web.WebView2.Wpf.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Data" />
     <Reference Include="System.Drawing" />
@@ -53,9 +64,6 @@
     <Compile Include="Controls\logo.xaml.cs">
       <DependentUpon>logo.xaml</DependentUpon>
     </Compile>
-    <Compile Include="MainControl.xaml.cs">
-      <DependentUpon>MainControl.xaml</DependentUpon>
-    </Compile>
     <Compile Include="MainWindow.xaml.cs">
       <DependentUpon>MainWindow.xaml</DependentUpon>
     </Compile>
@@ -79,6 +87,7 @@
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
     </EmbeddedResource>
+    <None Include="packages.config" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
       <LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -89,10 +98,6 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
-    <Page Include="MainControl.xaml">
-      <SubType>Designer</SubType>
-      <Generator>MSBuild:Compile</Generator>
-    </Page>
     <Page Include="MainWindow.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
@@ -103,4 +108,11 @@
     </Page>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Import Project="F:\NuGet\packages\Microsoft.Web.WebView2.1.0.2277.86\build\Microsoft.Web.WebView2.targets" Condition="Exists('F:\NuGet\packages\Microsoft.Web.WebView2.1.0.2277.86\build\Microsoft.Web.WebView2.targets')" />
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
+    </PropertyGroup>
+    <Error Condition="!Exists('F:\NuGet\packages\Microsoft.Web.WebView2.1.0.2277.86\build\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', 'F:\NuGet\packages\Microsoft.Web.WebView2.1.0.2277.86\build\Microsoft.Web.WebView2.targets'))" />
+  </Target>
 </Project>

+ 0 - 13
HTEXTeachLib/MainControl.xaml

@@ -1,13 +0,0 @@
-<UserControl x:Class="HTEXTeachLib.MainControl"
-             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
-             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             xmlns:local="clr-namespace:HTEXTeachLib"
-             mc:Ignorable="d" 
-             d:DesignHeight="450" d:DesignWidth="800">
-    <Grid>
-        <Button Content="Button" HorizontalAlignment="Left" Margin="210,225,0,0" VerticalAlignment="Top"/>
-
-    </Grid>
-</UserControl>

+ 0 - 28
HTEXTeachLib/MainControl.xaml.cs

@@ -1,28 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-
-namespace HTEXTeachLib
-{
-    /// <summary>
-    /// MainControl.xaml 的交互逻辑
-    /// </summary>
-    public partial class MainControl : UserControl
-    {
-        public MainControl()
-        {
-            InitializeComponent();
-        }
-    }
-}

+ 12 - 4
HTEXTeachLib/MainWindow.xaml

@@ -1,13 +1,21 @@
-<Window x:Class="HTEXTeachLib.MainWindow"
+<Window
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:HTEXTeachLib"
+        xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
+        x:Class="HTEXTeachLib.MainWindow"
         mc:Ignorable="d"
-        Title="MainWindow" Height="450" Width="800">
-    <Canvas>
-        <Button Content="Button" Canvas.Left="152" Canvas.Top="285"/>
+        Title="MainWindow" Height="450" Width="800" WindowStyle="None"  AllowsTransparency="True"  >
+    <Window.Background>
+        <!-- 1% 透明度的白色 -->
+        <SolidColorBrush Color="#01FFFFFF" />
+    </Window.Background>
+    <Canvas x:Name="myCanvas"  Background="Transparent"  Height="450" Width="800">
 
+        <Border BorderBrush="Gray" BorderThickness="0.5" CornerRadius="5" IsHitTestVisible="False">
+            <wv2:WebView2 Name="webView" Height="400" Width="400"  />
+        </Border>
     </Canvas>
 </Window>

+ 68 - 1
HTEXTeachLib/MainWindow.xaml.cs

@@ -1,4 +1,5 @@
-using System;
+using Microsoft.Web.WebView2.Core;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -17,11 +18,77 @@ namespace HTEXTeachLib
     /// <summary>
     /// MainWindow.xaml 的交互逻辑
     /// </summary>
+    ///WPF初探——利用Winform库中的NotifyIcon实现托盘小程序 
+    //https://blog.csdn.net/yahahi/article/details/112636760  倒计时器 (WPF)
+    ///https://www.cnblogs.com/royenhome/archive/2010/02/02/1662243.html
     public partial class MainWindow : Window
     {
         public MainWindow()
         {
             InitializeComponent();
+            var userDataFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Temp/webview2_temp");
+            var environment =  CoreWebView2Environment.CreateAsync(null, userDataFolder).Result;
+            // webView.EnsureCoreWebView2Async(environment);
+            webView.Loaded += WebView_CoreWebView2InitializationCompleted;
+            webView.PreviewDragOver  += WebView2_PreviewDragOver;
+            webView.Drop += WebView2_Drop;
+            webView.KeyDown+=sss;
+        }
+
+        private void sss(object sender, KeyEventArgs e)
+        {
+            DragMove();
+        }
+
+        private void WebView2_PreviewDragOver(object sender, DragEventArgs e)
+        {
+            // 检查拖拽的数据类型,如果是合适的类型,设置拖拽效果为 Copy 或 Move
+            //if (e.Data.GetDataPresent(DataFormats.Text))
+            //    e.Effects = DragDropEffects.Copy;
+            //else
+            //    e.Effects = DragDropEffects.None;
+            e.Effects = DragDropEffects.All;
+            e.Handled = true;
+        }
+
+        private void WebView2_Drop(object sender, DragEventArgs e)
+        {
+            // 获取拖拽的数据
+            string draggedText = e.Data.GetData(DataFormats.Text) as string;
+
+            // 在 WebView2 中执行相应的操作,例如插入文本
+            webView.ExecuteScriptAsync($"insertText('{draggedText}')");
+
+            e.Handled = true;
+           
+        }
+        private async void WebView_CoreWebView2InitializationCompleted(object sender, RoutedEventArgs e)
+        {
+            var userDataFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Temp/webview2_temp");
+            var environment = await CoreWebView2Environment.CreateAsync(null, userDataFolder);
+
+            await webView.EnsureCoreWebView2Async(environment);
+            string htmlContent = @"
+                <!DOCTYPE html>
+                <html>
+                <head>
+                    <style>
+                        body {
+                           background-color: transparent;
+                            margin: 0;
+                            padding: 0;
+                        }
+                    </style>
+                </head>
+                <body>
+                   <div>
+                    <img src='https://teammodeltest.blob.core.chinacloudapi.cn/0-public/007.png' alt='Irregular PNG Image'>
+                    </div>
+                    
+                </body>
+                </html>";
+            //webView.CoreWebView2.Navigate("C:/Users/CrazyIter/Downloads/clock.html");
+            webView.CoreWebView2.NavigateToString(htmlContent);
         }
     }
 }

+ 4 - 0
HTEXTeachLib/packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Microsoft.Web.WebView2" version="1.0.2277.86" targetFramework="net48" />
+</packages>