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
6 Answers, 1 is accepted
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
Ok thanks. Worked for me.
I guess you guys have your reasons for making the methods internal.
hi how do we apply the class. i have this class in my source. But i couldn't see this export function when i enter the control name
please see the screenshot[quote]Dimitar said: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
[/quote]
Open the designer file and replace the default RadGantView with the custom one. The attached image shows how you can do that.
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Progress Telerik
Hi,
I am trying to use you code, but I can get it the function radGanttView1.Export("path");
Am I missing something?
Many thanks,
Omar
I am not sure why this is not working on your side. I would recommend opening a support ticket and attaching your code. This way we will be able to properly investigate this case.
Should you have any other questions do not hesitate to ask.
Dimitar
Progress Telerik