Page 1 of 1

Print out to the paper center

Posted: Sat Oct 22, 2005 5:23 am
by 8122852
Hi,
I am trying to print out a chart image on to an A4 paper with some other graphical images, that is, I am trying to lay out several graphical objects on an A4 paper.

The problem is that I can not control the position and size of the TChart object image on the paper. The method available for this purpose seems to be only this one:
void TChart.Draw(System.Drawing.Graphics g)
Paints the Chart in your preferred Canvas and region.
But this method does not accept the position or size argument.
How can I do the size & position control on the paper?
Aren't there method similar to System.Drawing.Graphics.DrawImage?

Posted: Mon Oct 24, 2005 8:11 am
by narcis
Hi HotSteemar,

You could try doing something like on "All Features\Welcome !\Chart styles\Standard\Pie\Multiple Pies" example at the features demo. You'll find that example on TeeChart's program group.

Posted: Thu Oct 27, 2005 8:12 am
by 8122852
Hi,
Thank you for the advice, Narcis.
I do not quite understand the example yet.
So, currently what I am doing is like this:

Code: Select all

  private void button1_Click(object sender, System.EventArgs e)
  {
   this.tChart1.Export.Image.Bitmap.Save("temp.bmp");

   //PrintDocument
   System.Drawing.Printing.PrintDocument pd =
    new System.Drawing.Printing.PrintDocument();
   pd.PrintPage +=
    new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage);

   //PrintPreviewDialog
   PrintPreviewDialog ppd = new PrintPreviewDialog();
   ppd.Document = pd;
   //show PrintPreviewDialog
   ppd.ShowDialog();
  }

  private void pd_PrintPage(object sender,
   System.Drawing.Printing.PrintPageEventArgs e)
  {
   //image load
   e.Graphics.DrawString("Here comes a text sample.",
  new Font("MS UI Gothic",10),new
  System.Drawing.SolidBrush(Color.Red),10,10);

  // Here comes a TChart image:
   Image img = Image.FromFile("temp.bmp");
   e.Graphics.DrawImage(img, 100, 100, 600, 600);
   img.Dispose();
  }
Namely, the TChart area is first converted into a bitmap,
then the bitmap is rendered onto the graphics for the printer
by DrawImage() method at the specified location and size.
In this way, several objects can be laid out onto an A4 paper.

This method works well as long as the printer resolution is not
high compared with the resolution of the temporary TChart
bitmap. Otherwise, the printer result shows poor resolution
of the TChart area.

To avoid this awkward situation, I would like to know the way
to render TCharts directly onto graphics with controling the
location and size.
Could I have any more help?

Posted: Fri Oct 28, 2005 10:54 am
by narcis
Hi HotSteemar,

You should use a print document as shown on this FAQ's question.

Posted: Fri Nov 11, 2005 10:20 am
by 8122852
Thank you very much, Narcis.

I could control the position of the serveral objects on the printed papers.
Your advice helped me a lot.

Posted: Fri Nov 11, 2005 10:41 am
by narcis
Excellent HotSteemar. You're very welcome.