Page 1 of 1

Printer - Print title on page of 2 tcharts

Posted: Fri Jan 15, 2010 5:31 am
by 15654593
Hi,

I am printing 2 tcharts on one page. Now i want to add title to the page, so when it print out, it will have the title and the charts. How can i do it?
Thanks.

Regards,
Nicholas

Re: Printer - Print title on page of 2 tcharts

Posted: Fri Jan 15, 2010 5:09 pm
by yeray
Hi Nicholas,

Here is how you could do it:

Code: Select all

        private void InitializeChart()
        {            
            int MyWidth = 400;
            int MyHeight = 300;
            
            tChart1 = new Steema.TeeChart.TChart();
            this.Controls.Add(tChart1);
            tChart1.Top = 100;
            tChart1.Width = MyWidth;
            tChart1.Height = MyHeight;
            new Steema.TeeChart.Styles.Line(tChart1.Chart);
            tChart1[0].FillSampleValues();

            tChart2 = new Steema.TeeChart.TChart();
            this.Controls.Add(tChart2);
            tChart2.Left = MyWidth;
            tChart2.Top = 100;
            tChart2.Width = MyWidth;
            tChart2.Height = MyHeight;
            new Steema.TeeChart.Styles.Line(tChart2.Chart);
            tChart2[0].FillSampleValues();
            
            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);

            tChart1.Draw();
            tChart2.Draw();

            document.Print();
        }

        void document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Rectangle r1 = new Rectangle(0, 0, tChart1.Chart.Width, tChart1.Chart.Height);
            Rectangle r2 = new Rectangle(0, tChart1.Chart.Height, tChart2.Chart.Width, tChart2.Chart.Height);

            System.Drawing.Imaging.Metafile m = tChart1.Chart.Metafile(tChart1.Chart, r1.Width, r1.Height);
            System.Drawing.Imaging.Metafile m2 = tChart1.Chart.Metafile(tChart2.Chart, r2.Width, r2.Height);

            e.Graphics.DrawImage(m, r1, tChart1.Chart.ChartBounds, GraphicsUnit.Pixel);
            e.Graphics.DrawImage(m2, r2, tChart2.Chart.ChartBounds, GraphicsUnit.Pixel);

            Font myFont = new Font("Arial", 15, FontStyle.Bold);                        
            e.Graphics.DrawString("My charts", myFont, Brushes.Black, 20, tChart1.Chart.Height + tChart2.Chart.Height + 10);
        }

Re: Printer - Print title on page of 2 tcharts

Posted: Mon Jan 18, 2010 2:12 am
by 15654593
Hi Yeray,

Thank you. How about print preview? From print preview, there is a print button. Once i click on print button, it will print without my topic. How can i do that?

Regards,
Nicholas

Re: Printer - Print title on page of 2 tcharts

Posted: Tue Jan 19, 2010 3:20 pm
by narcis
Hi Nicholas,

You could try something like this.

I also strongly recommend you to read Tutorial14 - Printing Charts, specially the Print previewing several Charts on one page and Mixing printed Chart output with other print output sections. You'll find the tutorials at TeeChart's program group.

Hope this helps!