Printing OxyPlot example in WinForm

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

heromyth wrote at 2011-10-20 05:13:

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)); } }

 


objo wrote at 2011-10-20 08:05:

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

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


heromyth wrote at 2011-10-20 13:21:

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