private void btnPrint_Click(object sender, RoutedEventArgs e)
{
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
StackPanel stpanel;
stpanel = PrintStakPanel;
stpanel.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
Size grdSize = stpanel.DesiredSize;
Point grdPoint = new Point((dialog.PrintableAreaWidth - grdSize.Width) / 2, (dialog.PrintableAreaHeight - grdSize.Height) / 2);
stpanel.Arrange(new Rect(grdPoint, grdSize));
Grid.SetRow(stpanel, 0);
dialog.PrintVisual(stpanel, "Cinema Ticket");
}
}
Asked
Active
Viewed 3,393 times
1

AJ.
- 1,146
- 11
- 33

Abhilash Pandey
- 11
- 1
- 2
-
Format your code in a proper way. IF you post like this, no one will help. – Steven Wilson Oct 31 '12 at 06:57
-
Please add additional details of what you need help with instead of framing the entire question in the title – AJ. Oct 31 '12 at 07:16
-
in my Application thats a Cinema Application that is being developed in WPF, I have Film Tickets in a grid to be printed. Now the problem is that I dont want to open any Dialog(eg Print Dialog), i just want to click on "Print Ticket" button and all the tickets in the grid should be printed without asking for Page Layout etc – Abhilash Pandey Oct 31 '12 at 13:06
2 Answers
1
You can use PrintDialog
without doing a ShowDialog()
call....the currently set printer settings will just be used when you call PrintVisual
.
To do something more sophisticated, you can programmatically define the printer settings by using a PrintTicket
.
See here for more details:

Community
- 1
- 1

Colin Smith
- 12,375
- 4
- 39
- 47
-
Can i get some knowledge about PrintTicket Class. i m not getting whatever given in MSDN.. Please tell something about implementation of PrintTicket. – Abhilash Pandey Oct 31 '12 at 13:14