Print Ellipse : Print « Windows Presentation Foundation « C# / CSharp Tutorial






using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;


    public class PrintEllipse : Window
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new PrintEllipse());
        }
        public PrintEllipse()
        {
            StackPanel stack = new StackPanel();
            Content = stack;

            Button btn = new Button();
            btn.Content = "_Print...";
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.Margin = new Thickness(24);
            btn.Click += PrintOnClick;
            stack.Children.Add(btn);
        }
        void PrintOnClick(object sender, RoutedEventArgs args)
        {
            PrintDialog dlg = new PrintDialog();

            if ((bool)dlg.ShowDialog().GetValueOrDefault())
            {
                DrawingVisual vis = new DrawingVisual();
                DrawingContext dc = vis.RenderOpen();

                dc.DrawEllipse(Brushes.LightGray, new Pen(Brushes.Black, 3),
                               new Point(100,dlg.PrintableAreaHeight / 2),
                               200,dlg.PrintableAreaHeight / 2);

                dc.Close();
                dlg.PrintVisual(vis, "My first print job");
            }
        }            
    }








24.158.Print
24.158.1.Print Custom PagePrint Custom Page
24.158.2.Print Scaled VisualPrint Scaled Visual
24.158.3.Print a WPF VisualPrint a WPF Visual
24.158.4.Print Without User InterventionPrint Without User Intervention
24.158.5.Print Ellipse
24.158.6.Print Buttons