本文整理汇总了C#中System.Windows.Controls.PrintDialog类的典型用法代码示例。如果您正苦于以下问题:C# PrintDialog类的具体用法?C# PrintDialog怎么用?C# PrintDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PrintDialog类属于System.Windows.Controls命名空间,在下文中一共展示了PrintDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: cmdPrint_Click
private void cmdPrint_Click(object sender, RoutedEventArgs e)
{
PrintDialog pd = new PrintDialog();
if (pd.ShowDialog().GetValueOrDefault())
{
PrintTicket ticket = pd.PrintTicket;
if (cmboOrientation.SelectedIndex == 0)
{
ticket.PageOrientation = PageOrientation.Landscape;
}
else
{
ticket.PageOrientation = PageOrientation.Portrait;
}
pd.PrintTicket = ticket;
mDoc.PageHeight = pd.PrintableAreaHeight;
mDoc.PageWidth = pd.PrintableAreaWidth;
mDoc.PagePadding = new Thickness(50);
mDoc.ColumnGap = 0;
mDoc.ColumnWidth = pd.PrintableAreaWidth;
IDocumentPaginatorSource dps = mDoc;
pd.PrintDocument(dps.DocumentPaginator, title);
}
}
示例2: print_btn_Click
private void print_btn_Click(object sender, RoutedEventArgs e)
{
try
{
report.report_cr_dr p = new BMS.report.report_cr_dr();
p.lst_balance.ItemsSource = dr;
p.r_date.Content = DateTime.Now.Date.ToShortDateString();
p.r_name.Content = "Top Debitors";
PrintDialog pd = new PrintDialog();
FixedDocument document = new FixedDocument();
document.DocumentPaginator.PageSize = new Size(96 * 8.5, 96 * 11);
FixedPage page1 = new FixedPage();
page1.Width = document.DocumentPaginator.PageSize.Width;
page1.Height = document.DocumentPaginator.PageSize.Height;
Canvas can = p.layout;
page1.Children.Add(can);
PageContent page1Content = new PageContent();
((IAddChild)page1Content).AddChild(page1);
document.Pages.Add(page1Content);
pd.PrintDocument(document.DocumentPaginator, "My first document");
}
catch (Exception ex)
{
MessageBox.Show("Sorry some system error has occour please try again");
}
}
示例3: PrintPreview_Click
private void PrintPreview_Click(object sender, RoutedEventArgs e)
{
var printdialog = new PrintDialog();
if (printdialog.ShowDialog() != true) { return; }
var doc = new FixedDocument();
doc.DocumentPaginator.PageSize = new Size(printdialog.PrintableAreaWidth, printdialog.PrintableAreaHeight);
var queue = printdialog.PrintQueue;
var caps = queue.GetPrintCapabilities();
var area = caps.PageImageableArea;
var marginwidth = (printdialog.PrintableAreaWidth - caps.PageImageableArea.ExtentWidth) / 2.0;
var marginheight = (printdialog.PrintableAreaHeight - caps.PageImageableArea.ExtentHeight) / 2.0;
double gutter;
if (!Double.TryParse(GutterWidthTextbox.Text, out gutter)) { gutter = 0.25; }
// Translate inches to device independent pixels
gutter *= 96.0;
var opts = new PrintOptions
{
PrintableWidth = area.ExtentWidth,
PrintableHeight = area.ExtentHeight,
MarginWidth = marginwidth,
MarginHeight = marginheight,
Gutter = gutter
};
var category = (CardCategory)DataContext;
category.AddPagesToDocument(doc, opts, category.SelectedCards);
var preview = new PrintPreview();
preview.Document = doc;
preview.ShowDialog();
}
示例4: DoPrint
public override void DoPrint(FlowDocument document)
{
var ph = document.PageHeight;
var pw = document.PageWidth;
var pp = document.PagePadding;
var cg = document.ColumnGap;
var cw = document.ColumnWidth;
var q = PrinterInfo.GetPrinter(Printer.ShareName);
var pd = new PrintDialog { PrintQueue = q };
if (pd.PrintQueue.FullName == Printer.ShareName || pd.ShowDialog().GetValueOrDefault(false))
{
document.FontFamily = new System.Windows.Media.FontFamily(LocalSettings.PrintFontFamily);
document.Typography.EastAsianWidths = FontEastAsianWidths.Half;
document.PageHeight = pd.PrintableAreaHeight;
document.PageWidth = pd.PrintableAreaWidth;
document.PagePadding = new Thickness(25);
document.ColumnGap = 0;
document.ColumnWidth = (document.PageWidth -
document.ColumnGap -
document.PagePadding.Left -
document.PagePadding.Right);
pd.PrintDocument(((IDocumentPaginatorSource)document).DocumentPaginator, "");
}
document.PageHeight = ph;
document.PageWidth = pw;
document.PagePadding = pp;
document.ColumnGap = cg;
document.ColumnWidth = cw;
}
示例5: Print
/// <summary>
/// Prints this instance.
/// </summary>
public bool Print()
{
try
{
PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
bool? results = printDlg.ShowDialog();
if (results == null || results == false) return false;
//get selected printer capabilities
System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);
//get the size of the printer page
System.Windows.Size printSize = new System.Windows.Size(
capabilities.PageImageableArea.ExtentHeight, capabilities.PageImageableArea.ExtentWidth);
// Build print view
this.Height = printSize.Height;
this.Width = printSize.Width;
Measure(printSize);
Arrange(new System.Windows.Rect(printSize));
XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(printDlg.PrintQueue);
printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape;
xpsdw.WriteAsync(this);
}
catch (Exception ex)
{
MessageBox.Show(ex.GetBaseException().Message, "Printing Error", MessageBoxButton.OK, MessageBoxImage.Error);
return false;
}
return true;
}
示例6: PrintCommand
public void PrintCommand()
{
PrintDialog printDlg = new PrintDialog();
FlowDocument doc = new FlowDocument(new Paragraph(new Run(WebAddress))) {Name = "Directions"};
IDocumentPaginatorSource idpSource = doc;
printDlg.PrintDocument(idpSource.DocumentPaginator, "Directions Printing.");
}
示例7: DoPrint
public override void DoPrint(FlowDocument document)
{
var ph = document.PageHeight;
var pw = document.PageWidth;
var pp = document.PagePadding;
var cg = document.ColumnGap;
var cw = document.ColumnWidth;
var fm = document.FontFamily;
var bg = document.Background;
var q = PrinterInfo.GetPrinter(Printer.ShareName);
var pd = new PrintDialog { PrintQueue = q };
if (q != null || pd.PrintQueue.FullName == Printer.ShareName || Printer.ShareName.ToLower() == "default" || Printer.ShareName.Contains("/") || pd.ShowDialog().GetValueOrDefault(false))
{
document.Background = Brushes.Transparent;
document.FontFamily = new FontFamily(LocalSettings.PrintFontFamily);
document.PageHeight = pd.PrintableAreaHeight;
document.PageWidth = pd.PrintableAreaWidth;
document.PagePadding = new Thickness(25);
document.ColumnGap = 0;
document.ColumnWidth = (document.PageWidth -
document.ColumnGap -
document.PagePadding.Left -
document.PagePadding.Right);
pd.PrintDocument(((IDocumentPaginatorSource)document).DocumentPaginator, "");
}
document.Background = bg;
document.FontFamily = fm;
document.PageHeight = ph;
document.PageWidth = pw;
document.PagePadding = pp;
document.ColumnGap = cg;
document.ColumnWidth = cw;
}
示例8: btnPrint_Click
private void btnPrint_Click(object sender, RoutedEventArgs e)
{
//Show a Print Dialog
PrintDialog dialog = new PrintDialog();
dialog.MaxPage = this.pdfViewer1.PageCount > 0 ? (uint)this.pdfViewer1.PageCount : 1;
dialog.MinPage = 1;
dialog.UserPageRangeEnabled = true;
bool? result = dialog.ShowDialog();
if (result.Value)
{
try
{
//Set print parnameters.
this.pdfViewer1.PrintDialog = dialog;
//Get the PrintDocument.
dialog.PrintDocument(pdfViewer1.PrintDocument.DocumentPaginator, "Print Document");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
示例9: Print
public static void Print(FlowDocument printedPage)
{
PrintDialog dialog = new PrintDialog();
dialog.PrintTicket = dialog.PrintQueue.DefaultPrintTicket;
dialog.PrintTicket.PageOrientation = PageOrientation.Portrait;
dialog.PrintTicket.OutputQuality = OutputQuality.High;
dialog.PrintTicket.PageBorderless = PageBorderless.None;
dialog.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4);
if (dialog.ShowDialog() == true)
{
double pageHeight = printedPage.PageHeight;
double pageWidth = printedPage.PageWidth;
Thickness pagePadding = printedPage.PagePadding;
double columnGap = printedPage.ColumnGap;
double columnWidth = printedPage.ColumnWidth;
printedPage.PageHeight = dialog.PrintableAreaHeight;
printedPage.PageWidth = dialog.PrintableAreaWidth;
printedPage.PagePadding = new Thickness(50);
dialog.PrintDocument(((IDocumentPaginatorSource)printedPage).DocumentPaginator, "");
printedPage.PagePadding = pagePadding;
printedPage.PageHeight = pageHeight;
printedPage.PageWidth = pageWidth;
printedPage.ColumnWidth = columnWidth;
printedPage.ColumnGap = columnGap;
}
}
示例10: OnPrintCommand
protected override void OnPrintCommand()
{
PrintDialog printDialog = new PrintDialog();
printDialog.PrintQueue = LocalPrintServer.GetDefaultPrintQueue();
printDialog.PrintTicket = printDialog.PrintQueue.DefaultPrintTicket;
printDialog.PrintTicket.PageOrientation = PageOrientation;
if (printDialog.ShowDialog() == true)
{
// Code assumes this.Document will either by a FixedDocument or a FixedDocumentSequence
FixedDocument fixedDocument = this.Document as FixedDocument;
FixedDocumentSequence fixedDocumentSequence = this.Document as FixedDocumentSequence;
if (fixedDocument != null)
fixedDocument.PrintTicket = printDialog.PrintTicket;
if (fixedDocumentSequence != null)
fixedDocumentSequence.PrintTicket = printDialog.PrintTicket;
XpsDocumentWriter writer = PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue);
if (fixedDocument != null)
writer.WriteAsync(fixedDocument, printDialog.PrintTicket);
if (fixedDocumentSequence != null)
writer.WriteAsync(fixedDocumentSequence, printDialog.PrintTicket);
}
}
示例11: DoPrint
public override void DoPrint(FlowDocument document)
{
var ph = document.PageHeight;
var pw = document.PageWidth;
var pp = document.PagePadding;
var cg = document.ColumnGap;
var cw = document.ColumnWidth;
var q = PrinterInfo.GetPrinter(Printer.ShareName);
var pd = new PrintDialog { PrintQueue = q };
if (pd.PrintQueue.FullName == Printer.ShareName || pd.ShowDialog().GetValueOrDefault(false))
{
document.PageHeight = pd.PrintableAreaHeight;
document.PageWidth = pd.PrintableAreaWidth;
document.PagePadding = new Thickness(25);
document.ColumnGap = 0;
document.ColumnWidth = (document.PageWidth -
document.ColumnGap -
document.PagePadding.Left -
document.PagePadding.Right);
pd.PrintDocument(((IDocumentPaginatorSource)document).DocumentPaginator, "");
}
document.PageHeight = ph;
document.PageWidth = pw;
document.PagePadding = pp;
document.ColumnGap = cg;
document.ColumnWidth = cw;
}
示例12: UserControl_Loaded
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
var dialog = new PrintDialog();
document.DocumentPaginator.PageSize = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);
fixedPage = new FixedPage
{
Height = document.DocumentPaginator.PageSize.Height,
Width = document.DocumentPaginator.PageSize.Width
};
grid = new Grid();
grid.Arrange(new Rect(0, 0, fixedPage.Width, fixedPage.Height));
fixedPage.Children.Add(grid);
pageContent = new PageContent { Child = fixedPage };
pageContent.Arrange(new Rect(0, 0, fixedPage.Width, fixedPage.Height));
fixedPage.Margin = new Thickness(20, 44, 20, 44);
for (int i = 0; i < totalRows; i++)
{
grid.RowDefinitions.Add(new RowDefinition());
}
for (int j = 0; j < totalColumns; j++)
{
grid.ColumnDefinitions.Add(new ColumnDefinition());
}
document.Pages.Add(pageContent);
}
示例13: printOrder
public static void printOrder( Order o )
{
PrintDialog printDlg = new PrintDialog();
String textToPrint = "";
textToPrint += "\t\t Τραπέζι "+o.Table_id+"\n\n";
textToPrint += "Παραγγελία : \n";
String orderName = "";
foreach (Items i in DBController.LoadItems())
{
if (i.Id == o.Items_id)
orderName = i.Name;
}
orderName += o.CharacteristicsInfo;
textToPrint += "\t1 "+orderName+"\n";
textToPrint += "\n\n";
String waiterName = "";
foreach (User u in DBController.LoadUsers())
{
if (u.User_id == o.User_id)
waiterName = u.Name;
}
textToPrint += "Σερβιτόρος : "+waiterName+"\n";
textToPrint += "Ώρα : " + DateTime.Now.ToString("dd/MM/yyyy h:mm:ss tt");
FlowDocument doc = new FlowDocument(new Paragraph(new Run(textToPrint)));
doc.Name = "FlowDoc";
IDocumentPaginatorSource idpSource = doc;
printDlg.PrintDocument(idpSource.DocumentPaginator, "smart order");
}
示例14: Print_Click
private void Print_Click(object sender, RoutedEventArgs e)
{
//If you reduce the size of the view area of the window, so the text does not all fit into one page, it will print separate pages
PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
printDialog.PrintDocument(((IDocumentPaginatorSource)flowDocument).DocumentPaginator, "This is a Flow Document");
}
示例15: cmdPrintCustom_Click
private void cmdPrintCustom_Click(object sender, RoutedEventArgs e)
{
PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
FlowDocument doc = docReader.Document;
// Save all the existing settings.
double pageHeight = doc.PageHeight;
double pageWidth = doc.PageWidth;
Thickness pagePadding = doc.PagePadding;
double columnGap = doc.ColumnGap;
double columnWidth = doc.ColumnWidth;
// Make the FlowDocument page match the printed page.
doc.PageHeight = printDialog.PrintableAreaHeight;
doc.PageWidth = printDialog.PrintableAreaWidth;
doc.PagePadding = new Thickness(50);
// Use two columns.
doc.ColumnGap = 25;
doc.ColumnWidth = (doc.PageWidth - doc.ColumnGap
- doc.PagePadding.Left - doc.PagePadding.Right) / 2;
printDialog.PrintDocument(((IDocumentPaginatorSource)doc).DocumentPaginator, "A Flow Document");
// Reapply the old settings.
doc.PageHeight = pageHeight;
doc.PageWidth = pageWidth;
doc.PagePadding = pagePadding;
doc.ColumnGap = columnGap;
doc.ColumnWidth = columnWidth;
}
}