本文整理汇总了C#中System.Windows.Controls.PrintDialog.PrintVisual方法的典型用法代码示例。如果您正苦于以下问题:C# PrintDialog.PrintVisual方法的具体用法?C# PrintDialog.PrintVisual怎么用?C# PrintDialog.PrintVisual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.PrintDialog
的用法示例。
在下文中一共展示了PrintDialog.PrintVisual方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Button_Click
private void Button_Click(object sender, RoutedEventArgs e)
{
Common.Print(printedPage);
PrintDialog printDlg = new PrintDialog();
printDlg.PrintVisual(mygrid, "Grid Printing.");
}
示例2: Print
public Int32 Print()
{
var dlg = new PrintDialog();
if (dlg.ShowDialog() == true)
{
//---FIRST PAGE---//
// Size the Grid.
Content.Measure(new Size(Double.PositiveInfinity,
Double.PositiveInfinity));
Size sizeGrid = Content.DesiredSize;
//check the width
if (sizeGrid.Width > dlg.PrintableAreaWidth)
{
MessageBoxResult result = MessageBox.Show("Some Items are out of printable area", "Print",
MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.No)
throw new PrintDialogException("print aborted");
}
// Position of the grid
var ptGrid = new Point(HorizontalOffset, VerticalOffset);
// Layout of the grid
Content.Arrange(new Rect(ptGrid, sizeGrid));
//print
dlg.PrintVisual(Content, Title);
//---MULTIPLE PAGES---//
//---MULTIPLE PAGES---//
double diff;
int i = 1;
while ((diff = sizeGrid.Height - (dlg.PrintableAreaHeight - VerticalOffset*i)*i) > 0)
{
//Position of the grid
var ptSecondGrid = new Point(HorizontalOffset, -sizeGrid.Height + diff + VerticalOffset);
// Layout of the grid
Content.Arrange(new Rect(ptSecondGrid, sizeGrid));
//print
int k = i + 1;
dlg.PrintVisual(Content, Title + " (Page " + k + ")");
i++;
}
return i;
}
throw new PrintDialogException("print aborted");
}
示例3: PrintOnClick
void PrintOnClick(object sender, RoutedEventArgs args)
{
PrintDialog dlg = new PrintDialog();
if ((bool)dlg.ShowDialog().GetValueOrDefault())
{
// Create DrawingVisual and open DrawingContext.
DrawingVisual vis = new DrawingVisual();
DrawingContext dc = vis.RenderOpen();
// Draw ellipse.
dc.DrawEllipse(Brushes.LightGray, new Pen(Brushes.Black, 3),
new Point(dlg.PrintableAreaWidth / 2,
dlg.PrintableAreaHeight / 2),
dlg.PrintableAreaWidth / 2,
dlg.PrintableAreaHeight / 2);
// Close DrawingContext.
dc.Close();
// Finally, print the page.
dlg.PrintVisual(vis, "My first print job");
}
}
示例4: PrintDocumentVis
public void PrintDocumentVis(Bitmap bm, string DocumentName)
{
DrawingVisual vis = new DrawingVisual();
DrawingContext dc = vis.RenderOpen();
BitmapImage imgSource = new BitmapImage();
using (MemoryStream memory = new MemoryStream())
{
bm.Save(memory, ImageFormat.Png);
memory.Position = 0;
imgSource.BeginInit();
imgSource.StreamSource = memory;
imgSource.CacheOption = BitmapCacheOption.OnLoad;
imgSource.EndInit();
}
dc.DrawImage(imgSource, new Rect(0, 0, imgSource.Width, imgSource.Height));
dc.Close();
PrintDialog pdDialog = new PrintDialog();
pdDialog.PrintVisual(vis, DocumentName);
// Cleanup
vis = null;
dc = null;
imgSource = null;
pdDialog = null;
}
示例5: Print
public static void Print(Grid 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.Height;
double pageWidth = printedPage.Width;
printedPage.Height = dialog.PrintableAreaHeight;
printedPage.Width = dialog.PrintableAreaWidth;
dialog.PrintVisual(printedPage, "");
printedPage.Height = pageHeight;
printedPage.Width = pageWidth;
}
}
示例6: PrintDialog
void IUIJob.OnNewOperation(IOperationViewer operationViewer, Operation operation)
{
// Only print if we don't have already (verrrrrrrrrrrry helpful during debugging, but also a sanity-check)
if (CheckIsOperationAlreadyPrinted(operation, true))
{
return;
}
PrintQueue printQueue = _printQueue.Value;
// If printing is not possible (an error occurred because the print server is not available etc.).
if (printQueue == null)
{
Logger.Instance.LogFormat(LogType.Warning, this, "Cannot print job because the configured printer seems not available! Check log entries.");
return;
}
// We need to wait for a bit to let the UI "catch a breath".
// Otherwise, if printing immediately, it may have side-effects that parts of the visual aren't visible (bindings not updated etc.).
Thread.Sleep(_configuration.WaitInterval);
PrintDialog dialog = new PrintDialog();
dialog.PrintQueue = printQueue;
dialog.PrintTicket = dialog.PrintQueue.DefaultPrintTicket;
dialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
dialog.PrintTicket.CopyCount = _configuration.CopyCount;
FrameworkElement visual = operationViewer.Visual;
// Measure and arrange the visual before printing otherwise it looks unpredictably weird and may not fit on the page
visual.Measure(new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight));
visual.Arrange(new Rect(new Point(0, 0), visual.DesiredSize));
dialog.PrintVisual(visual, "New alarm " + operation.OperationNumber);
}
示例7: PrintPageDialog
private void PrintPageDialog(Messages.PrintPage printMessage)
{
PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);
//get scale of the print wrt to screen of WPF visual
double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / this.ActualWidth, capabilities.PageImageableArea.ExtentHeight / this.ActualHeight);
//Transform the Visual to scale
this.LayoutTransform = new ScaleTransform(scale, scale);
//get the size of the printer page
Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
//update the layout of the visual to the printer page size.
printMessage.Element.Measure(sz);
printMessage.Element.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));
//now print the visual to printer to fit on the one page.
printDialog.PrintVisual(printMessage.Element, printMessage.Description);
}
}
示例8: AskToPrint
public static void AskToPrint( FrameworkElement ctrl
, string printJobDesc = "Scaled Visual")
{
PrintDialog print = new PrintDialog();
if (print.ShowDialog() != true) return;
PrintCapabilities capabilities = print.PrintQueue.GetPrintCapabilities(print.PrintTicket);
double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / ctrl.ActualWidth,
capabilities.PageImageableArea.ExtentHeight / ctrl.ActualHeight);
//Transform oldTransform = ctrl.LayoutTransform;
ctrl.LayoutTransform = new ScaleTransform(scale, scale);
//Size oldSize = new Size(ctrl.ActualWidth, ctrl.ActualHeight);
Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
ctrl.Measure(sz);
((UIElement)ctrl).Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight),
sz));
ctrl.Focus();
print.PrintVisual(ctrl, printJobDesc);
//ctrl.LayoutTransform = oldTransform;
//ctrl.Measure(oldSize);
//((UIElement)ctrl).Arrange(new Rect(new Point(0, 0),
// oldSize));
}
示例9: PrintVisual
public static void PrintVisual(Grid g)
{
printDialog = new PrintDialog();
if (printDialog.ShowDialog() == false)
return;
FrameworkElement e = g as FrameworkElement;
Transform originalScale = e.LayoutTransform;
//get selected printer capabilities
PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);
//get scale of the print wrt to screen of WPF visual
double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / g.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
g.ActualHeight);
//Transform the Visual to scale
g.LayoutTransform = new ScaleTransform(scale, scale);
//get the size of the printer page
Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
//update the layout of the visual to the printer page size.
g.Measure(sz);
g.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));
//now print the visual to printer to fit on the one page.
printDialog.PrintVisual(g, "Onion Smart Solutions");
e.LayoutTransform = originalScale;
}
示例10: AskToPrint
public static void AskToPrint( ContentPresenter content
, string printJobDesc = "Tab Content Visual")
{
var dlg = new PrintDialog();
if (dlg.ShowDialog() != true) return;
dlg.PrintVisual(content, printJobDesc);
}
示例11: Print
public void Print()
{
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
dialog.PrintVisual(grdMain, "Social Network Analysis");
}
}
示例12: Button_Click
private void Button_Click(object sender, RoutedEventArgs e)
{
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
dialog.PrintVisual(printArea, "Print Demo");
}
}
示例13: button1_Click
private void button1_Click(object sender, RoutedEventArgs e)
{
PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog().GetValueOrDefault(false))
{
printDialog.PrintVisual(this, this.Title);
}
}
示例14: Print_Click
private void Print_Click(object sender, RoutedEventArgs e)
{
var dlg = new PrintDialog();
if (dlg.ShowDialog().GetValueOrDefault())
{
dlg.PrintVisual(view1.Viewport, this.Title);
}
}
示例15: Print
public void Print(Visual visual, string description)
{
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog().GetValueOrDefault())
{
dialog.PrintVisual(visual, description);
}
}