Printing Displays Black Background
Posted: Wed Mar 26, 2008 2:23 pm
When I print a chart with the Legend visible set to false I get a black background. This only happens on the second time I print the chart. The first time I print it the background is correct.
private void button2_Click(object sender, EventArgs e)
{
//printPreviewDialog1.all
//printPreviewDialog1.ShowDialog();
System.Drawing.Printing.PrintDocument document = new System.Drawing.Printing.PrintDocument();
document.PrintController = new System.Drawing.Printing.StandardPrintController();
document.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(document_PrintPage);
uxChart.Legend.Visible = false;
//document.Print();
printPreviewDialog1.PrintPreviewControl.Document = document;
printPreviewDialog1.ShowDialog();
}
void document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//Remove the boarder
uxChart.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None;
uxChart.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
//save the current configuration of the chart
bool panelGradient = uxChart.Panel.Gradient.Visible;
//bool wallsTransparant = _currentDisplayedChart.Walls.Back.Transparent;
Color panelColor = uxChart.Panel.Color;
//set parameters so that the background will display white when printing
uxChart.Panel.Gradient.Visible = false;
uxChart.Walls.Back.Transparent = true;
uxChart.Panel.Color = Color.White;
//capture the screen in a stream
MemoryStream fs = new MemoryStream();
uxChart.Chart.Export.Image.PNG.Save(fs);
Image img = Image.FromStream(fs, false, false);
uxChart.Legend.Visible = false;
e.Graphics.DrawImage(img, e.MarginBounds.X, e.MarginBounds.Y, e.MarginBounds.Width, e.MarginBounds.Height);
//restore defaults
uxChart.Panel.Gradient.Visible = panelGradient;
uxChart.Walls.Back.Transparent = false;
uxChart.Panel.Color = panelColor;
}
private void button2_Click(object sender, EventArgs e)
{
//printPreviewDialog1.all
//printPreviewDialog1.ShowDialog();
System.Drawing.Printing.PrintDocument document = new System.Drawing.Printing.PrintDocument();
document.PrintController = new System.Drawing.Printing.StandardPrintController();
document.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(document_PrintPage);
uxChart.Legend.Visible = false;
//document.Print();
printPreviewDialog1.PrintPreviewControl.Document = document;
printPreviewDialog1.ShowDialog();
}
void document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//Remove the boarder
uxChart.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None;
uxChart.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
//save the current configuration of the chart
bool panelGradient = uxChart.Panel.Gradient.Visible;
//bool wallsTransparant = _currentDisplayedChart.Walls.Back.Transparent;
Color panelColor = uxChart.Panel.Color;
//set parameters so that the background will display white when printing
uxChart.Panel.Gradient.Visible = false;
uxChart.Walls.Back.Transparent = true;
uxChart.Panel.Color = Color.White;
//capture the screen in a stream
MemoryStream fs = new MemoryStream();
uxChart.Chart.Export.Image.PNG.Save(fs);
Image img = Image.FromStream(fs, false, false);
uxChart.Legend.Visible = false;
e.Graphics.DrawImage(img, e.MarginBounds.X, e.MarginBounds.Y, e.MarginBounds.Width, e.MarginBounds.Height);
//restore defaults
uxChart.Panel.Gradient.Visible = panelGradient;
uxChart.Walls.Back.Transparent = false;
uxChart.Panel.Color = panelColor;
}