Exemplo n.º 1
0
        private void Print(device target)
        {
            PrintDialog printDlg = new PrintDialog();

            if (printDlg.ShowDialog() == true)
            {
                Size      pageSize  = new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight);
                Transform transform = new RotateTransform(0);;

                /*
                 * if(printDlg.PrintTicket.PageOrientation == System.Printing.PageOrientation.Landscape)
                 * {
                 *  transform = new RotateTransform(90);
                 * }
                 * else
                 * {
                 *  transform = new RotateTransform(0);
                 * }
                 */

                UserControl print;
                string      name = string.Empty;

                if (target == device.stick)
                {
                    print = new Stick(null);
                    name  = "Warthog Stick";
                }
                else if (target == device.stickHornet)
                {
                    print = new StickHornet(null);
                    name  = "F/A-18C Hornet Stick";
                }
                else
                {
                    print = new Throttle(null);
                    name  = "Warthog Throttle";
                }

                print.Margin          = new Thickness(printDlg.PrintableAreaWidth * 0.03);
                print.LayoutTransform = transform;
                ((IControlSet)print).SetSet(controls);
                print.Measure(pageSize);
                print.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));



                printDlg.PrintVisual(print, "WarthogChart " + name);
                ((IControlSet)print).CleanUp();
            }
        }
Exemplo n.º 2
0
        private void SwitchToStickHornet()
        {
            if (controlSet != null)
            {
                UpdateControls(controlSet.GetSet());
                controlSet.CleanUp();
            }

            StickHornet stick = new StickHornet(this);

            controlSet = stick;
            controlSet.SetSet(controls);
            grd_diagram.Content = stick;
        }
Exemplo n.º 3
0
        private void Export(device target)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.DefaultExt = ".png";
            dlg.Filter     = "PNG files (.png)|*.png";

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                UserControl export;

                if (target == device.stick)
                {
                    export = new Stick(null);
                }
                else if (target == device.stickHornet)
                {
                    export = new StickHornet(null);
                }
                else
                {
                    export = new Throttle(null);
                }

                try
                {
                    Size pageSize = new Size(453 * 10, 605 * 10);

                    ((IControlSet)export).SetSet(controls);
                    export.Measure(pageSize);
                    export.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));

                    RenderTargetBitmap rtb = new RenderTargetBitmap((int)export.ActualWidth, (int)export.ActualHeight, 96, 96, PixelFormats.Pbgra32);
                    DrawingVisual      dv  = new DrawingVisual();
                    using (DrawingContext ctx = dv.RenderOpen())
                    {
                        VisualBrush vb = new VisualBrush(export);
                        ctx.DrawRectangle(vb, null, new Rect(new Point(), pageSize));
                    }
                    rtb.Render(dv);

                    PngBitmapEncoder png = new PngBitmapEncoder();
                    png.Frames.Add(BitmapFrame.Create(rtb));

                    using (Stream fileStream = new FileStream(dlg.FileName, FileMode.Create))
                    {
                        png.Save(fileStream);
                    }
                }
                catch
                {
                    MessageBox.Show(this, "Error occured during chart export saving!", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                }
                finally
                {
                    ((IControlSet)export).CleanUp();
                }
            }
        }