Beispiel #1
0
/*
 *      private void Canvas_Drop(object sender, DragEventArgs e)
 *      {
 *          UIElement element = null;
 *          if (e.Data.GetData(typeof(BarCode)).GetType()== typeof(BarCode))
 *          {
 *              element = e.Data.GetData(typeof(BarCode)) as BarCode;
 *          }
 *          else if (e.Data.GetData(typeof(TextBlock)).GetType() == typeof(TextBlock))
 *          {
 *              element = e.Data.GetData(typeof(TextBlock)) as TextBlock;
 *          }
 *          else if (e.Data.GetData(typeof(Line)).GetType() == typeof(Line))
 *          {
 *              element = e.Data.GetData(typeof(Line)) as Line;
 *          }
 *          else if (e.Data.GetData(typeof(Rectangle)).GetType() == typeof(Rectangle))
 *          {
 *              element = e.Data.GetData(typeof(Rectangle)) as Rectangle;
 *          }
 *
 *          if (element == null) return;
 *          if (mainCanvas.Children.Count >= 0)
 *          {
 *              Console.WriteLine(element);
 *              mainCanvas.Children.Add(element);
 *              Canvas.SetTop(element, e.GetPosition(this.mainCanvas).Y);
 *              Canvas.SetLeft(element, e.GetPosition(this.mainCanvas).X);
 *          }
 *          dragStartPoint = null;
 *          selectedBrush = null;
 *          RemoveDraggedAdorner();
 *          e.Handled = true;
 *      }
 *
 *      public static bool IsMovementBigEnough(Point initialMousePosition, Point currentPosition)
 *      {
 *          return (Math.Abs(currentPosition.X - initialMousePosition.X) >= SystemParameters.MinimumHorizontalDragDistance ||
 *               Math.Abs(currentPosition.Y - initialMousePosition.Y) >= SystemParameters.MinimumVerticalDragDistance);
 *      }
 *
 *      private void ToolBar_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 *      {
 *          dragStartPoint = new Point?(Mouse.GetPosition(this));
 *      }
 *
 *      private int dragCount = 0;//ToolBar_PreviewMouseMove会被触发两次,剔除其中一次
 *      private void ToolBar_PreviewMouseMove(object sender, MouseEventArgs e)
 *      {
 *          if (dragStartPoint.HasValue && e.LeftButton == MouseButtonState.Pressed)
 *          {
 *              if (IsMovementBigEnough(dragStartPoint.Value, e.GetPosition(this)))
 *              {
 *                  Button btn = selectedBrush as Button;
 *                  if (btn == null) return;
 *                  this.initialMouseOffset = this.dragStartPoint.Value - btn.TranslatePoint(new Point(0, 0), this);
 *
 *                  DataObject dataObject = new DataObject();
 *                  if (btn.Name == "btnBarcode")
 *                  {
 *                      BarCode barCode = new BarCode("1234567");
 *                      dataObject.SetData(barCode);
 *                  }
 *                  else if (btn.Name == "btnText")
 *                  {
 *                      TextBlock tb = new TextBlock();
 *                      tb.AllowDrop = true;
 *                      tb.Text = "12345678";
 *                      dataObject.SetData(tb);
 *                  }
 *                  else if (btn.Name == "btnLine")
 *                  {
 *                      Line line = new Line();
 *                      line.Height = 1;
 *                      line.Width = 100;
 *                      line.X1 = 10;
 *                      line.X2 = 110;
 *                      line.Y1 = 20;
 *                      line.Y2 = 10;
 *                      line.Fill = Brushes.Black;
 *                      dataObject.SetData(line);
 *                  }
 *                  else if (btn.Name == "btnRect")
 *                  {
 *                      Rectangle rectangle = new Rectangle();
 *                      rectangle.Height = 50;
 *                      rectangle.Width = 100;
 *                      rectangle.Fill = Brushes.Transparent;
 *                      dataObject.SetData(rectangle);
 *                  }
 *                  else if (btn.Name == "btnImg")
 *                  {
 *
 *                  }
 *                  try
 *                  {
 *                      dragCount++;
 *                      if (dragCount == 2)
 *                      {
 *                          DragDrop.DoDragDrop(this.toolBar, dataObject, DragDropEffects.Copy);
 *                          dragCount = 0;
 *                      }
 *                  }
 *                  catch { }
 *              }
 *          }
 *          else
 *          {
 *              selectedBrush = null;
 *          }
 *          e.Handled = true;
 *      }
 *
 *      private void mainCanvas_PreviewDragEnter(object sender, DragEventArgs e)
 *      {
 *          BarCode bc = e.Data.GetData(typeof(BarCode)) as BarCode;
 *          if (bc != null)
 *          {
 *              //ShowDraggedAdorner(e.GetPosition(this));
 *          }
 *          e.Handled = true;
 *      }
 *
 *      private void mainCanvas_PreviewDragOver(object sender, DragEventArgs e)
 *      {
 *          BarCode bc = e.Data.GetData(typeof(BarCode)) as BarCode;
 *          if (bc != null)
 *          {
 *              //ShowDraggedAdorner(e.GetPosition(this));
 *          }
 *          e.Handled = true;
 *      }
 *
 *
 *
 *      private void mainCanvas_PreviewDragLeave(object sender, DragEventArgs e)
 *      {
 *          RemoveDraggedAdorner();
 *          e.Handled = true;
 *      }
 *
 */
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            this.Topmost = false;
            this.mainCanvas.Background = Brushes.White;
            // Display Printer dialog for user to
            // choose the printer to output to.
            XpsPrintHelper printHelper = new XpsPrintHelper(this.mainCanvas);
            PrintDialog    printDialog = printHelper.GetPrintDialog();

            if (printDialog == null)
            {
                return;     //user selected cancel
            }
            PrintQueue printQueue = printDialog.PrintQueue;

            printHelper.OnAsyncPrintChange += new XpsPrintHelper.AsyncPrintChangeHandler(AsyncPrintEvent);
            printHelper.PrintVisualAsync(printQueue);

            this.Topmost = true;
        }
Beispiel #2
0
        // ------------------------ ButtonHelperPrint -------------------------
        /// <summary>
        ///   Saves the current DocumentViewer content either
        ///   synchronously (waiting for completion) or
        ///   asynchronously (not waiting for completion).</summary>
        /// <param name="async">
        ///   true to save asynchronously; false to save synchronously.</param>
        private void ButtonHelperPrint(bool async)
        {
            // Display Printer dialog for user to
            // choose the printer to output to.
            XpsPrintHelper printHelper = new XpsPrintHelper(_contentDir);
            PrintDialog    printDialog = printHelper.GetPrintDialog();

            if (printDialog == null)
            {
                return;     //user selected cancel
            }
            PrintQueue printQueue = printDialog.PrintQueue;

            if (async)
            {
                _printHelper = printHelper;

                //Make progress controls visible
                AsyncPrintLabel.Visibility    = Visibility.Visible;
                AsyncPrintProgress.Visibility = Visibility.Visible;
                AsyncPrintStatus.Visibility   = Visibility.Visible;

                //register for async archiving events
                _printHelper.OnAsyncPrintChange +=
                    new XpsPrintHelper.AsyncPrintChangeHandler(AsyncPrintEvent);

                AsyncPrintProgress.Value = 10;
                AsyncPrintStatus.Text    = "Async Print Initiated";

                UIEnabled(false, false, true);
            }// end:if (async)

            // Print the DocumentViewer's current content.
            switch (currentMode)
            {
            case eGuiMode.SingleVisual:
            {
                printHelper.PrintSingleVisual(printQueue, async);
                break;
            }

            case eGuiMode.MultipleVisuals:
            {
                printHelper.PrintMultipleVisuals(printQueue, async);
                break;
            }

            case eGuiMode.SingleFlowDocument:
            {
                printHelper.PrintSingleFlowContentDocument(
                    printQueue, async);
                break;
            }

            case eGuiMode.SingleFixedDocument:
            {
                printHelper.PrintSingleFixedContentDocument(
                    printQueue, async);
                break;
            }

            case eGuiMode.MultipleFixedDocuments:
            {
                printHelper.PrintMultipleFixedContentDocuments(
                    printQueue, async);
                break;
            }
            } // end:switch (currentMode)
        }     // end:ButtonHelperSave()