Programmatically Export GanttView to File

3 posts, 0 answers
  1. Yemo
    Yemo avatar
    13 posts
    Member since:
    Sep 2006

    Posted 17 Mar Link to this post

    Hello,

    Please advise whteher there is an available code sample on how to use the following specified method in winforms

    IImageExporter..::..ExportToImage Method 

    http://doc.evget.com/HelpDocument/RadControlsForWpf/html/M_Telerik_Windows_Controls_GanttView_IImageExporter_ExportToImage.htm

    or any alternative routine to achieve the same desired effect.

    Many thanks

  2. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 21 Mar Link to this post

    Hello Yemi,

    Thank you for writing.

    We have internal methods that can export the Gantt to an image, they are used for printing. Here is how you can use them to create an image:
    class MyGantt : RadGanttView
    {
        public void Export(string path)
        {
            GanttViewTraverser traverser = new GanttViewTraverser(this.GanttViewElement);
            traverser.TraverseAllItems = true;
            List<GanttViewDataItem> flatItemsCollection = new List<GanttViewDataItem>();
     
            while (traverser.MoveNext())
            {
                flatItemsCollection.Add(traverser.Current);
            }
            float height = flatItemsCollection.Count * this.ItemHeight + this.HeaderHeight;
            float width = (float)((this.GanttViewElement.GraphicalViewElement.TimelineBehavior.AdjustedTimelineEnd.AddDays(1) - this.GanttViewElement.GraphicalViewElement.TimelineBehavior.AdjustedTimelineStart).TotalSeconds /
              (float)this.GanttViewElement.GraphicalViewElement.OnePixelTime.TotalSeconds);
             
            Bitmap bmp = new Bitmap((int)width,(int)height);
            int columnsWidth = 0;
     
            foreach (GanttViewTextViewColumn col in this.Columns)
            {
                if (col.Visible)
                {
                    columnsWidth += col.Width;
                }
            }
     
            this.drawArea = new RectangleF(0, 0, columnsWidth, 100);
     
            using (Graphics grp = Graphics.FromImage(bmp))
            {
                grp.FillRectangle( Brushes.White, 0, 0, bmp.Width, bmp.Height);
            }
     
            this.DrawTextViewAndGraphicalViewToBitmap(bmp);
            this.DrawHeaderAndTimelineViewToBitmap(bmp);
            bmp.Save(path);
     
        }
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Yemo
    Yemo avatar
    13 posts
    Member since:
    Sep 2006

    Posted 22 Mar in reply to Dimitar Link to this post

    Ok thanks. Worked for me.

    I guess you guys have your reasons for making the methods internal.

Back to Top