Printing OxyPlot example in WinForm

Oct 20, 2011 at 4:13 AM
Here are some code snippets for Printing OxyPlot. 
The OxyPlot can be printed into a partial section in the cava.
There also including another way exporting the OxyPlot to PNG.

======================================= private void printPreviewBtn_Click(object sender, EventArgs e) { PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Document = reportPrintDocument; ppd.ShowDialog(); } private void reportPrintDocument_PrintPage(object sender, PrintPageEventArgs e) { Graphics graphBoard = e.Graphics; float sectionWidth = e.PageBounds.Width; PointF strLocation = new PointF(); strLocation.X = 50f; strLocation.Y = 50f; graphBoard.DrawString("Test Text",new Font("Tahoma", 16, FontStyle.Bold), Brushes.Black, strLocation); int width = (int)sectionWidth - 10; int height = 300; width = plot1.Width; height = plot1.Height; Bitmap bm = new Bitmap(width, height); plot1.DrawToBitmap(bm, new Rectangle(0,0,width,height)); bm.Save("C:\\test.bmp"); bm.Save("C:\\test.png", ImageFormat.Png); graphBoard.DrawImage(bm, new Point(50, 150)); } }

 

Coordinator
Oct 20, 2011 at 7:05 AM

thank you, I will include this in one of the examples!

(I think the definintion of reportPrintDocument is missing in your code)

Oct 20, 2011 at 12:21 PM
Edited Oct 20, 2011 at 12:22 PM
objo wrote:

thank you, I will include this in one of the examples!

(I think the definintion of reportPrintDocument is missing in your code)

reportPrintDocument = new System.Drawing.Printing.PrintDocument();

You can drag a PrintDocument control from the VS's Toolbox