Printer - Print title on page of 2 tcharts

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
nicholasamh
Newbie
Newbie
Posts: 8
Joined: Wed Nov 04, 2009 12:00 am

Printer - Print title on page of 2 tcharts

Post by nicholasamh » Fri Jan 15, 2010 5:31 am

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

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Printer - Print title on page of 2 tcharts

Post by Yeray » Fri Jan 15, 2010 5:09 pm

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);
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

nicholasamh
Newbie
Newbie
Posts: 8
Joined: Wed Nov 04, 2009 12:00 am

Re: Printer - Print title on page of 2 tcharts

Post by nicholasamh » Mon Jan 18, 2010 2:12 am

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

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

Re: Printer - Print title on page of 2 tcharts

Post by Narcís » Tue Jan 19, 2010 3:20 pm

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!
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

Post Reply