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;
}
Printing Displays Black Background
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi history,
I could reproduce the problem here and works fine for me here using a Metafile instead of a PNG as shown in the code below. Could you please try if it works fine for you?
Thanks in advance.
I could reproduce the problem here and works fine for me here using a Metafile instead of a PNG as shown in the code below. Could you please try if it works fine for you?
Code: Select all
void document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//Remove the boarder
tChart1.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None;
tChart1.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
//save the current configuration of the chart
bool panelGradient = tChart1.Panel.Gradient.Visible;
//bool wallsTransparant = _currentDisplayedChart.Walls.Back.Transparent;
Color panelColor = tChart1.Panel.Color;
//set parameters so that the background will display white when printing
tChart1.Panel.Gradient.Visible = false;
tChart1.Walls.Back.Transparent = true;
tChart1.Panel.Color = Color.White;
//capture the screen in a stream
System.IO.MemoryStream fs = new System.IO.MemoryStream();
//tChart1.Chart.Export.Image.PNG.Save(fs);
tChart1.Chart.Export.Image.Metafile.Save(fs);
fs.Position = 0;
Image img = Image.FromStream(fs, false, false);
tChart1.Legend.Visible = false;
e.Graphics.DrawImage(img, e.MarginBounds.X, e.MarginBounds.Y, e.MarginBounds.Width, e.MarginBounds.Height);
//restore defaults
tChart1.Panel.Gradient.Visible = panelGradient;
tChart1.Walls.Back.Transparent = false;
tChart1.Panel.Color = panelColor;
}
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |