本文整理汇总了C#中System.Windows.Controls.PrintDialog.ShowDialog方法的典型用法代码示例。如果您正苦于以下问题:C# PrintDialog.ShowDialog方法的具体用法?C# PrintDialog.ShowDialog怎么用?C# PrintDialog.ShowDialog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.PrintDialog
的用法示例。
在下文中一共展示了PrintDialog.ShowDialog方法的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: 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();
}
示例3: 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;
}
示例4: btnPrint_Click_1
private void btnPrint_Click_1(object sender, RoutedEventArgs e)
{
var printControl = new SummaryControl();
printControl.DataContext = _reservation;
printControl.Width = 8.27 * 96;
printControl.Height = 11.69 * 96;
//Create a fixed Document and Print the document
FixedDocument fixedDoc = new FixedDocument();
PageContent pageContent = new PageContent();
FixedPage fixedPage = new FixedPage();
fixedPage.Height = 11.69 * 96;
fixedPage.Width = 8.27 * 96;
fixedPage.Children.Add(printControl);
((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage);
fixedDoc.Pages.Add(pageContent);
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
//dialog.PrintVisual(_PrintCanvas, "My Canvas");
dialog.PrintDocument(fixedDoc.DocumentPaginator, "Print label");
}
}
示例5: 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);
}
}
示例6: 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);
}
}
}
示例7: PrintDialog
/// <summary>
/// Invokes a System.Windows.Controls.PrintDialog to print the TextEditor.Document with specified title.
/// </summary>
public static void PrintDialog(this TextEditor textEditor, string title)
{
Printing.mDocumentTitle = title;
Printing.InitPageSettings();
System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
printDialog.PrintQueue = mPrintQueue;
if (mPageSettings.Landscape)
Printing.mPrintTicket.PageOrientation = PageOrientation.Landscape;
printDialog.PrintTicket = mPrintTicket;
printDialog.PrintQueue.DefaultPrintTicket.PageOrientation = mPrintTicket.PageOrientation;
if (printDialog.ShowDialog() == true)
{
Printing.mPrintQueue = printDialog.PrintQueue;
Printing.mPrintTicket = printDialog.PrintTicket;
printDialog.PrintDocument(CreateDocumentPaginatorToPrint(textEditor), "PrintJob");
}
}
示例8: 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");
}
示例9: btnPrint_Click
private void btnPrint_Click(object sender, EventArgs e)
{
//REFACTOR ME
dtgParentReport.Update();
System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
Nullable<bool> print = printDialog.ShowDialog();
if (print == true)
{
try
{
XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
printDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
}
catch (UnauthorizedAccessException e1)
{
const string message =
"Unauthoried to access that printer.";
const string caption = "Unauthoried Access";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
catch (PrintDialogException e2)
{
const string message =
"Unknow error occurred.";
const string caption = "Error Printing";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
示例10: 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;
}
}
示例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: 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;
}
示例13: OnPrintCommand
protected override void OnPrintCommand()
{
// get a print dialog, defaulted to default printer and default printer's preferences.
var printDialog = new PrintDialog();
printDialog.PrintQueue = LocalPrintServer.GetDefaultPrintQueue();
printDialog.PrintTicket = printDialog.PrintQueue.DefaultPrintTicket;
string s = Document.GetType().ToString();
// get a reference to the FixedDocumentSequence for the viewer.
//FixedDocumentSequence docSeq = this.Document as FixedDocumentSequence;
var docSeq = (FixedDocument) Document;
// set the default page orientation based on the desired output.
printDialog.PrintTicket = (PrintTicket) docSeq.PrintTicket;
if (printDialog.ShowDialog() == true)
{
// set the print ticket for the document sequence and write it to the printer.
docSeq.PrintTicket = printDialog.PrintTicket;
var writer = PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue);
writer.WriteAsync(docSeq, printDialog.PrintTicket);
}
}
示例14: PrintOnClick
void PrintOnClick(object sender, RoutedEventArgs args)
{
PrintDialog dlg = new PrintDialog();
if (dlg.ShowDialog().GetValueOrDefault())
{
// Make sure orientation is Portrait.
PrintTicket prntkt = dlg.PrintTicket;
prntkt.PageOrientation = PageOrientation.Portrait;
dlg.PrintTicket = prntkt;
// Create new BannerDocumentPaginator object.
BannerDocumentPaginator paginator = new BannerDocumentPaginator();
// Set Text property from TextBox.
paginator.Text = txtbox.Text;
// Give it a PageSize property based on the paper dimensions.
paginator.PageSize = new Size(dlg.PrintableAreaWidth,
dlg.PrintableAreaHeight);
// Call PrintDocument to print the document.
dlg.PrintDocument(paginator, "Banner: " + txtbox.Text);
}
}
示例15: 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;
}