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

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Windows Presentation Foundation » Print 
24.158.6.Print Buttons
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;


    public class PrintaBunchaButtons : Window
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new PrintaBunchaButtons());
        }
        public PrintaBunchaButtons()
        {
            SizeToContent = SizeToContent.WidthAndHeight;
            ResizeMode = ResizeMode.CanMinimize;

            Button btn = new Button();
            btn.Content = "Print ...";
            btn.Click += PrintOnClick;
            Content = btn;
        }
        void PrintOnClick(object sender, RoutedEventArgs args)
        {
            PrintDialog dlg = new PrintDialog();

            if ((bool)dlg.ShowDialog().GetValueOrDefault())
            {
                Grid grid = new Grid();
                for (int i = 0; i < 5; i++)
                {
                    ColumnDefinition coldef = new ColumnDefinition();
                    coldef.Width = GridLength.Auto;
                    grid.ColumnDefinitions.Add(coldef);

                    RowDefinition rowdef = new RowDefinition();
                    rowdef.Height = GridLength.Auto;
                    grid.RowDefinitions.Add(rowdef);
                }
                grid.Background =  new LinearGradientBrush(Colors.Gray, Colors.White,
                                            new Point(00)new Point(11));

                for (int i = 0; i < 5; i++)
                {
                    Button btn = new Button();
                    btn.Content = "Button No. " (i + 1);
                    btn.HorizontalAlignment = HorizontalAlignment.Center;
                    btn.VerticalAlignment = VerticalAlignment.Center;
                    btn.Margin = new Thickness(6);
                    grid.Children.Add(btn);
                    Grid.SetRow(btn, i % 5);
                    Grid.SetColumn(btn, i / 5);
                }
                grid.Measure(new Size(Double.PositiveInfinity,
                                      Double.PositiveInfinity));

                Size sizeGrid = grid.DesiredSize;

                Point ptGrid = new Point((dlg.PrintableAreaWidth - sizeGrid.Width2,
                              (dlg.PrintableAreaHeight - sizeGrid.Height2);

                grid.Arrange(new Rect(ptGrid, sizeGrid));
                dlg.PrintVisual(grid, Title);
            }
        }
    }
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.