private void Window_Loaded(object sender, RoutedEventArgs e) { for (int i = App.LstPaths.Count - 1; i >= 0; i--) { if (!File.Exists(App.LstPaths[i])) { App.LstPaths.RemoveAt(i); } } LstPPT.ItemsSource = App.LstPaths; if (PPT.TryGetApplication() != null) { TurnToWdPPT(); } }
/// <summary> /// PPT还打开吗? /// </summary> private bool IsPPtOpened() { return(PPT.TryGetApplication() != null); }
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;//默认选择鼠标模式 }