elektra Posted April 16, 2010 Report Share Posted April 16, 2010 - We have decided to buy ChartFX7 in the next few days and the company's name and logo in the bottom of each page are required, when the chart is printed.That's why I tried the following Code : void chart1_InternalCommand(object sender, ChartFX.WinForms.CommandUIEventArgs e) { if (e.CommandId == chart1.Commands[CommandId.PrintDialog].ID) { PrintDocument printDoc = new PrintDocument(); printDoc.PrintPage += new PrintPageEventHandler(pd_PrintPage); chart1.Printer.Document = printDoc; chart1.Printer.ForceColors = true; chart1.Printer.Compress = true; } } void pd_PrintPage(object sender, PrintPageEventArgs e) { e.Graphics.DrawString("Company's name", new Font("Arial", 14, FontStyle.Bold), Brushes.Black, 25, 25, StringFormat.GenericTypographic); chart1.Paint(e.Graphics, new Rectangle(0, 0, e.MarginBounds.Width, e.MarginBounds.Height), PaintStyles.Print); } => Result: I had the following problems: 1) It take a lot of time until the chart is printed 2) the chart is printed, but It looks very strange, HUGE MARKERS, WRONG DATETIME FORMAT, a little bit LEFT ALIGNED => I want to have the same default-printed View but with a Company's name and Logo CAN ANY ONE HELP ME? thx in advance Quote Link to comment Share on other sites More sharing options...
juanZ Posted April 16, 2010 Report Share Posted April 16, 2010 Hi, please check and test this code. Let me know if this helped. public partial class Form1 : Form { private MemoryStream chartStream; public Form1() { InitializeComponent(); } /// <summary> /// Export Chart to a desired DPI resolution. /// </summary> /// <param name="dpi"></param> private void ChartToStream(int dpi) { // where the chart will be saved. chartStream = new MemoryStream(); // GDI Container for the chart. Rectangle r = new Rectangle(0, 0, (chart1.Width * dpi) / 96, (chart1.Height * dpi) / 96); // 96 is the screen resolution Bitmap bmp = new Bitmap(r.Width, r.Height); // Set resolution and initialize graphics object. bmp.SetResolution(dpi, dpi); Graphics g = Graphics.FromImage(bmp); chart1.Paint(g, r, PaintStyles.Background | PaintStyles.Border | PaintStyles.Print); bmp.Save(chartStream, ImageFormat.Jpeg); // Can also use PNG // Release resouces. g.Dispose(); bmp.Dispose(); } private void button1_Click(object sender, EventArgs e) { ChartToStream(96); //96 DPI PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); pd.Print(); } void pd_PrintPage(object sender, PrintPageEventArgs e) { // Include generated image. e.Graphics.DrawImage(Image.FromStream(chartStream), e.MarginBounds.Left, e.MarginBounds.Top); } } Quote Link to comment Share on other sites More sharing options...
elektra Posted April 20, 2010 Author Report Share Posted April 20, 2010 I have realized it with this code, it works: void chart1_InternalCommand(object sender,ChartFX.WinForms.CommandUIEventArgs e) { if (e.CommandId == chart1.Commands[CommandId.PrintDialog].ID) { chart1.Printer.Document.PrintPage += new PrintPageEventHandler(pd_PrintPage); chart1.Printer.Margins.Top = 100; // Place where th logo will be printed chart1.Printer.ForceColors = true; chart1.Printer.Compress = true; } } void pd_PrintPage(object sender, PrintPageEventArgs e) { e.Graphics.DrawImage( Image.FromFile("logo.bmp"), new Point(e.PageBounds.X , e.PageBounds.Y)); return;} Thank you for the reply we have already ordered ChartFX. Quote Link to comment Share on other sites More sharing options...
juanZ Posted April 20, 2010 Report Share Posted April 20, 2010 Im glad the product worked. If you have any question, just write us back, Best Regards, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.