Printing Displays Black Background

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
history
Newbie
Newbie
Posts: 29
Joined: Tue May 22, 2007 12:00 am

Printing Displays Black Background

Post by history » 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;

}

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Mar 27, 2008 10:37 am

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?

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;
		}
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

history
Newbie
Newbie
Posts: 29
Joined: Tue May 22, 2007 12:00 am

Post by history » Thu Mar 27, 2008 1:25 pm

That worked, I was also able to correct the issue by setting the Transparent to 100 and then back to 0.

Thanks

Post Reply