Skip to content

Commit 09f0bfe

Browse files
authored
FAQ: "Printing Plots with Windows Forms" updated to use ScottPlot 5 (#49)
1 parent 3a397bc commit 09f0bfe

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

content/faq/print.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Printing Plots with Windows Forms - ScottPlot FAQ
33
description: How to print a plot using ScottPlot
4-
date: 2023-12-13
4+
date: 2025-02-12
55
---
66

77
# Printing Plots with Windows Forms
@@ -10,29 +10,29 @@ date: 2023-12-13
1010

1111
![](/images/faq/print/print-preview.png)
1212

13-
{{< code-sp4 >}}
14-
1513
```cs
1614
public Form1()
1715
{
1816
InitializeComponent();
19-
formsPlot1.Plot.AddSignal(ScottPlot.DataGen.Sin(51));
20-
formsPlot1.Plot.AddSignal(ScottPlot.DataGen.Cos(51));
17+
formsPlot1.Plot.Add.Signal(Generate.Sin(51));
18+
formsPlot1.Plot.Add.Signal(Generate.Cos(51));
2119
}
2220

2321
private void PrintPage(object sender, PrintPageEventArgs e)
2422
{
2523
// Determine how large you want the plot to be on the page and resize accordingly
2624
int width = e.MarginBounds.Width;
2725
int height = (int)(e.MarginBounds.Width * .5);
28-
formsPlot1.Plot.Resize(width, height);
2926

3027
// Give the plot a white background so it looks good on white paper
31-
formsPlot1.Plot.Style(figureBackground: Color.White);
28+
formsPlot1.Plot.FigureBackground.Color = Colors.White;
3229

3330
// Render the plot as a Bitmap and draw it onto the page
34-
Bitmap bmp = formsPlot1.Plot.Render();
35-
e.Graphics.DrawImage(bmp, e.MarginBounds.Left, e.MarginBounds.Top);
31+
using (var ms = new MemoryStream(formsPlot1.Plot.GetImageBytes(width, height)))
32+
{
33+
Bitmap bmp = new Bitmap(ms);
34+
e.Graphics.DrawImage(bmp, e.MarginBounds.Left, e.MarginBounds.Top);
35+
}
3636
}
3737

3838
private void btnPrint_Click(object sender, EventArgs e)
@@ -53,5 +53,3 @@ private void btnPrintPreview_Click(object sender, EventArgs e)
5353
printDialog.ShowDialog();
5454
}
5555
```
56-
57-
{{< /code-sp4 >}}

0 commit comments

Comments
 (0)