예제 #1
0
 private void ButtonUP_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         slideIndex = slide.SlideIndex - 1;
     }
     catch
     {
         WdMessageBox.Display("Error", "PPT已关闭", "真是不幸");
         App.Current.Shutdown();
     }
     if (slideIndex >= 1)
     {
         try
         {
             slide = slides[slideIndex];
             slides[slideIndex].Select();
         }
         catch
         {
             // 在阅读模式下使用下面的方式来切换到上一张幻灯片
             pptApplication.SlideShowWindows[1].View.Previous();
             slide = pptApplication.SlideShowWindows[1].View.Slide;
         }
     }
     else
     {
         slideIndex = 1;
         WdMessageBox.Display("Info", "已经到了第一页", "", "", "哦");
     }
     UpdateSlideIndex();
 }
예제 #2
0
 private void ButtonDown_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         slideIndex = slide.SlideIndex + 1;
     }
     catch
     {
         WdMessageBox.Display("Error", "PPT已关闭", "真是不幸");
         App.Current.Shutdown();
     }
     if (slideIndex > slidesCount)
     {
         WdMessageBox.Display("Info", "已经到了最后一页", "", "", "哦");
         slideIndex = slidesCount;
     }
     else
     {
         try
         {
             slide = slides[slideIndex];
             slides[slideIndex].Select();
         }
         catch
         {
             // 在阅读模式下使用下面的方式来切换到下一张幻灯片
             pptApplication.SlideShowWindows[1].View.Next();
             slide = pptApplication.SlideShowWindows[1].View.Slide;
         }
     }
     UpdateSlideIndex();
 }
예제 #3
0
 private void RemoveAPoint()
 {
     if (Tps.Count > 0)
     {
         Tps.RemoveAt(Tps.Count - 1);
         UpdateEpsAndRs();
     }
     else
     {
         WdMessageBox.Display("消息", "无法再撤销了");
     }
 }
예제 #4
0
        private async void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            if (Tps.Count % 2 != 0)
            {
                await WdMessageBox.Display("消息", "请选中偶数个点", "", "", "知道了");

                return;
            }
            await Task.Run(() =>
            {
                TbInfo.Dispatcher.Invoke(() =>
                {
                    TbInfo.Text = "切割图片中";
                });
                BtnSave.Dispatcher.Invoke(() =>
                {
                    BtnSave.IsEnabled = false;
                });
                List <Bitmap> bs = new List <Bitmap>();
                for (int i = 0; i < maxPgIndex + 1; i++)
                {
                    var tps  = (from x in Tps where x.PgIndex == i select x).ToList();
                    Bitmap b = new Bitmap(Dir_WorkPlace + $"temp/{i}.jpg");
                    var t    = ImageHelper.EditImages(b, tps);
                    bs       = bs.Concat(t).ToList();
                    b.Dispose();
                }


                string dir_pic = Dir_WorkPlace + @"pics\";
                if (Directory.Exists(dir_pic))
                {
                    Directory.Delete(dir_pic, true);
                }
                Directory.CreateDirectory(dir_pic);
                for (int i = 0; i < bs.Count; i++)
                {
                    bs[i].Save($@"{dir_pic}{i}.jpg");
                }
                TbInfo.Dispatcher.Invoke(() =>
                {
                    TbInfo.Text = "生成DOC中";
                });
                WordHelper.WriteWord($@"{App.Dir_Desktop}{TimeStamp.Now}.docx", dir_pic);
                TbInfo.Dispatcher.Invoke(() =>
                {
                    TbInfo.Text = "运行中";
                });
            });

            BtnSave.IsEnabled = true;
        }
예제 #5
0
        private static async void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            try
            {
                Logger.WriteException(e.Exception, "试图恢复UI异常");
                e.Handled = true;
                ExpectionCatched?.Invoke(null, e.Exception);
            }
#pragma warning disable CA1031 // 不捕获常规异常类型
            catch (Exception)
#pragma warning restore CA1031 // 不捕获常规异常类型
            {
                Logger.WriteLine("Error,不可恢复的UI异常", "Bad");
                await WdMessageBox.Display("消息", "很遗憾,我们遇到了一个无法挽回的错误,程序即将关闭,希望联系开发人员以改善程序质量", "确认").ConfigureAwait(false);
            }
        }
예제 #6
0
        private async void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            var i = await WdMessageBox.Display("消息", "真的要删除所有点吗?不过会留下备份的.", "", "取消", "删除");

            if (i == 2)
            {
                File.Copy(File_tpstxt, File_tpstxt + TimeStamp.Now);
                Tps = new ObservableCollection <TPoint>();
                SaveTps();
                Tps.CollectionChanged += (sd, arg) =>
                {
                    SaveTps();
                };
                UpdateEpsAndRs();
            }
        }
예제 #7
0
        private static async void AppDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                if (e.ExceptionObject is Exception exception)
                {
                    Logger.WriteException(exception, "试图恢复非UI异常");
                    ExpectionCatched?.Invoke(null, exception);
                }
            }
#pragma warning disable CA1031 // 不捕获常规异常类型
            catch (Exception)
#pragma warning restore CA1031 // 不捕获常规异常类型
            {
                Logger.WriteLine("Error,不可恢复的非UI异常");
                await WdMessageBox.Display("消息", "很遗憾,我们遇到了一个无法挽回的错误,程序即将关闭,希望联系开发人员以改善程序质量", "确认").ConfigureAwait(false);
            }
        }
예제 #8
0
        private async void BtnTest_Click(object sender, RoutedEventArgs e)
        {
            int index = int.Parse(((Button)sender).Tag.ToString());

            Console.WriteLine($"TestIndex={index}");
            switch (index)
            {
            case 0:
                var result = await WdMessageBox.Display("消息", "消息", "OK");

                Console.WriteLine(result);
                break;

            case 1:
                KeyboardHook keyboardHook = new KeyboardHook();
                keyboardHook.KeyDown += KeyboardHook_KeyDown;
                break;

            default:
                Console.WriteLine("未提供测试方法");
                break;
            }
        }
예제 #9
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < 8; i++)
            {
                pptApplication = PPT.TryGetApplication();
                if (pptApplication != null)
                {
                    break;
                }
                System.Threading.Thread.Sleep(2000);
            }
            if (pptApplication == null)
            {
                WdMessageBox.Display("错误", "即将关闭,请打开PPT再打开本软件");
                App.Current.Shutdown();
            }

            //获得演示文稿对象
            presentation = pptApplication.ActivePresentation;
            // 获得幻灯片对象集合
            slides = presentation.Slides;
            // 获得幻灯片的数量
            slidesCount = slides.Count;

            inks = new InkCanvas[slidesCount + 1];//slideIndex从1开始
            for (int i = 0; i < inks.Length; i++)
            {
                inks[i] = new InkCanvas
                {
                    Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)),
                };
                inks[i].SetValue(Grid.RowSpanProperty, 2);
                GMain.Children.Add(inks[i]);
            }
            Canvas.SetZIndex(GBottom, 1);
            DispatcherTimer dispatcherTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromSeconds(1), IsEnabled = true
            };

            dispatcherTimer.Tick += (sder, arg) =>
            {
                if (!IsPPtOpened())
                {
                    PPtClosed();
                    return;
                }
                UpdateSlideIndex();

                if (!IsPPtOpened())
                {
                    PPtClosed();
                    return;
                }
                try
                {
                    TbInfo.Text = $"name={presentation.Name}{Environment.NewLine}" +
                                  $"slideIndex={slideIndex}";
                    string s = slideIndex.ToString() + "/" + slidesCount.ToString();
                    LbLeft.Content  = s;
                    LbRight.Content = s;
                }
                catch (Exception ex)
                {
                    TLib.Software.Logger.WriteException(ex);
                }
            };
            Color[] colors = new Color[] { Colors.Black, Colors.DarkGray, Colors.Gray, Colors.LightGray, Colors.White,
                                           Colors.Red, Colors.OrangeRed, Colors.Orange, Colors.Gold, Colors.Yellow,
                                           Colors.LawnGreen, Colors.Green, Colors.SeaGreen, Colors.DeepSkyBlue, Colors.Blue,
                                           Colors.Tomato, Colors.Violet, Colors.LightYellow, Colors.LightGreen, Colors.LightBlue,
                                           Colors.Pink, Colors.RosyBrown, Colors.Chocolate, Colors.Brown, Colors.Purple, };
            for (int i = 0; i < btnsColor.Length; i++)
            {
                btnsColor[i] = new Button
                {
                    Background = new SolidColorBrush(colors[i]),
                    Name       = "BtnColor" + i
                };
                btnsColor[i].Click += (s, arg) =>
                {
                    Button b     = (Button)s;
                    int    index = int.Parse(b.Name.Substring(8));
                    for (int t = 0; t < btnsColor.Length; t++)
                    {
                        if (index == t)
                        {
                            btnsColor[t].BorderThickness = new Thickness(2);
                        }
                        else
                        {
                            btnsColor[t].BorderThickness = new Thickness(0);
                        }
                    }
                    foreach (var item in inks)
                    {
                        item.DefaultDrawingAttributes.Color = colors[index];
                    }
                };
                UGColor.Children.Add(btnsColor[i]);
                //Grid.SetColumn(btns[i],0);
                //Grid.SetRow(btns[i], 0);
            }
            SelectedIndex = 0;//默认选择鼠标模式
        }