I am using Measurement Studio v 8.1 inside Visual Studio 2005. I reviewed online help as well as the example code for printing found in the Measurement Studio help folders for Visual Studio 2005 and have managed to get a printout of my scattergraph data and both the x-axis and y-axis. I have not yet been able to figure out how to get a print out of the gridlines for the x-axis and y-axis. Below is the relevant code. A button is pressed (btnPrint) and the plot in the form is printed to the default printer and sized according to the printer settings. Any help would be greatly appreciated.
Regards,
Peter
private void btnPrint_Click(object sender, EventArgs e)
{
using (PrintDocument document = new PrintDocument())
{
document.PrintPage += GetPrintPageEventHandler();
document.Print();
}
}
private PrintPageEventHandler GetPrintPageEventHandler()
{
PrintPageEventHandler handler = new PrintPageEventHandler(PrintPageCalibrationData);
return handler;
}
private void PrintPageCalibrationData(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
Rectangle plotBounds, xAxisBounds, yAxisBounds;
GetElementBounds(e, out plotBounds, out xAxisBounds, out yAxisBounds);
xAxis1.Draw(new ComponentDrawArgs(g, xAxisBounds), XAxisPosition.Bottom);
yAxis1.Draw(new ComponentDrawArgs(g, yAxisBounds), YAxisPosition.Left);
// We need to draw the division lines here.
// Draw plot outline
g.DrawRectangle(new Pen(Brushes.Black), plotBounds);
scatterPlot1.Draw(new ComponentDrawArgs(g, plotBounds));
}
private void GetElementBounds(PrintPageEventArgs e, out Rectangle plotBounds, out Rectangle xAxisBounds, out Rectangle yAxisBounds)
{
Graphics g = e.Graphics;
// Find page dimensions and resize bounding rectangle accordingly
Rectangle bounds = Rectangle.Inflate(e.MarginBounds, 0, -2 * e.PageSettings.Margins.Top);
Rectangle originalXAxisBounds = xAxis1.GetBounds();
Rectangle originalYAxisBounds = yAxis1.GetBounds();
plotBounds = new Rectangle(bounds.X + originalYAxisBounds.Width, bounds.Y + originalXAxisBounds.Height, bounds.Width - originalYAxisBounds.Width, bounds.Height - (originalXAxisBounds.Height * 2));
xAxisBounds = xAxis1.GetBounds(g, plotBounds);
yAxisBounds = yAxis1.GetBounds(g, plotBounds);
}