Beispiel #1
0
 private void New()
 {
     if (isSaved == false)
     {
         if (MessageBox.Show("尚未保存,真的要新建画板吗?", "新建确认", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
         {
             canvas1.Children.Clear();
             canvas1.InvalidateVisual();
             du = new DrawingUIElement();
             compositeGraphic.Clear();
             canvas1.Children.Add(du);
             du_refresh();
             isSaved = false;
         }
     }
     else
     {
         canvas1.Children.Clear();
         canvas1.InvalidateVisual();
         du = new DrawingUIElement();
         compositeGraphic.Clear();
         canvas1.Children.Add(du);
         du_refresh();
         isSaved = false;
     }
 }
Beispiel #2
0
 private void Open()
 {
     if (MessageBox.Show("载入图片将会清空当前内容,真的要载入图片吗?", "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         canvas1.Children.Clear();
         canvas1.InvalidateVisual();
         du = new DrawingUIElement();
         compositeGraphic.Clear();
         canvas1.Children.Add(du);
         du_refresh();
         isSaved = false;
         OpenFileDialog dlg = new OpenFileDialog();
         dlg.CheckFileExists = true;
         dlg.Filter = "所有格式 (*.*)|*.*|矢量图 (*.eps)|*.eps|位图 (*.bmp)|*.bmp";
         if ((bool)dlg.ShowDialog(this))
         {
             canvas1.Children.Clear();
             try
             {
                 using (FileStream file = new FileStream(dlg.FileName,
                                             FileMode.Open, FileAccess.Read))
                 {
                     if (!(dlg.FileName.ToLower().EndsWith(".png") || dlg.FileName.ToLower().EndsWith(".bmp") || dlg.FileName.ToLower().EndsWith(".eps") || dlg.FileName.ToLower().EndsWith(".jpg")))
                     {
                         MessageBox.Show("图片格式不符合要求", Title);
                     }
                     else
                     {
                         Uri url = new Uri(dlg.FileName);
                         BitmapImage bmp = new BitmapImage(url);
                         System.Windows.Controls.Image img = new System.Windows.Controls.Image();
                         img.Source = bmp;
                         img.Height = canvas1.Height;
                         img.Width = canvas1.Width;
                         img.Stretch = Stretch.Uniform;
                         canvas1.Children.Add(img);
                         canvas1.Children.Remove(du);
                         canvas1.Children.Add(du);
                         file.Close();
                     }
                 }
             }
             catch (Exception exc)
             {
                 MessageBox.Show(exc.Message, Title);
             }
         }
     }
 }