Mini Kabibi Habibi
using System;
using System.Drawing.Imaging;
using System.Windows.Forms;
using DevExpress.DXperience.Demos;
using DevExpress.Utils.Menu;
using DevExpress.XtraBars;
using DevExpress.XtraCharts.Printing;
namespace DevExpress.XtraCharts.Demos {
public class TutorialControl : TutorialControlBase {
IDXMenuManager menuManager;
ImageFormat currentImageFormat;
public IDXMenuManager MenuManager {
get { return menuManager; }
set { menuManager = value; }
}
public ChartRibbonMenuManager ChartRibbonMenuManager { get { return RibbonMenuManager as ChartRibbonMenuManager; } }
public virtual ChartControl ChartControl { get { return null; } }
public override bool AllowPrintOptions { get { return ChartControl != null; } }
protected override void AllowExport() {
EnabledPrintExportActions(true,
ExportFormats.ImageEx | ExportFormats.PDF | ExportFormats.HTML | ExportFormats.MHT | ExportFormats.XLS | ExportFormats.RTF | ExportFormats.XLSX, false);
}
protected override void ExportToCore(string filename, string ext) {
ChartControl chart = ChartControl;
if (chart != null) {
Cursor currentCursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
if (ext == "rtf")
chart.ExportToRtf(filename);
else if (ext == "pdf")
chart.ExportToPdf(filename);
else if (ext == "mht")
chart.ExportToMht(filename);
else if (ext == "html")
chart.ExportToHtml(filename);
else if (ext == "xls")
chart.ExportToXls(filename);
else if (ext == "xlsx")
chart.ExportToXlsx(filename);
else
chart.ExportToImage(filename, currentImageFormat);
Cursor.Current = currentCursor;
}
}
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
if (ParentFormMain != null) {
BarSubItem exportItem = ((frmMain)ParentFormMain).ExportToImageExButton;
exportItem.ClearLinks();
AddImageFormat(exportItem, ImageFormat.Bmp);
AddImageFormat(exportItem, ImageFormat.Emf);
AddImageFormat(exportItem, ImageFormat.Exif);
AddImageFormat(exportItem, ImageFormat.Gif);
AddImageFormat(exportItem, ImageFormat.Icon);
AddImageFormat(exportItem, ImageFormat.Jpeg);
AddImageFormat(exportItem, ImageFormat.Png);
AddImageFormat(exportItem, ImageFormat.Tiff);
AddImageFormat(exportItem, ImageFormat.Wmf);
}
}
protected override void ExportToPDF() {
ChartControl chart = ChartControl;
if (chart != null) {
PrintSizeMode sizeMode = chart.OptionsPrint.SizeMode;
chart.OptionsPrint.SizeMode = PrintSizeMode.Zoom;
try {
ExportTo("pdf", "PDF document (*.pdf)|*.pdf");
}
finally {
chart.OptionsPrint.SizeMode = sizeMode;
}
}
}
protected override void ExportToHTML() {
ExportTo("html", "HTML document (*.html)|*.html");
}
protected override void ExportToMHT() {
ExportTo("mht", "MHT document (*.mht)|*.mht");
}
protected override void ExportToXLS() {
ExportTo("xls", "XLS document (*.xls)|*.xls");
}
protected override void ExportToXLSX() {
ExportTo("xlsx", "XLSX document (*.xlsx)|*.xlsx");
}
protected override void ExportToRTF() {
ExportTo("rtf", "RTF document (*.rtf)|*.rtf");
}
protected override void ExportToText() {
ExportTo("txt", "Text document (*.txt)|*.txt");
}
protected override void PrintPreview() {
ChartControl chart = ChartControl;
if (chart != null) {
chart.OptionsPrint.SizeMode = PrintSizeMode.Zoom;
if (RibbonMenuManager.PrintOptions.ShowRibbonPreviewForm)
chart.ShowRibbonPrintPreview();
else
chart.ShowPrintPreview();
}
}
void AddImageFormat(BarSubItem biImagesMenuItem, ImageFormat format) {
ImageCodecInfo codecInfo = FindImageCodec(format);
if (codecInfo != null) {
BarExportToImageItem item = new BarExportToImageItem(Manager, format, codecInfo);
item.ItemClick += new ItemClickEventHandler(OnExportImageClick);
biImagesMenuItem.AddItem(item);
}
}
ImageCodecInfo FindImageCodec(ImageFormat format) {
ImageCodecInfo[] infos = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo item in infos)
if (item.FormatID.Equals(format.Guid))
return item;
return null;
}
void OnExportImageClick(object sender, ItemClickEventArgs e) {
BarExportToImageItem item = e.Item as BarExportToImageItem;
if (item != null) {
currentImageFormat = item.ImageFormat;
ExportTo(item.ImageCodecInfo.FilenameExtension,
String.Format("{0} ({1})|{1}", String.Format("{0} image", item.ImageCodecInfo.FormatDescription), item.ImageCodecInfo.FilenameExtension));
}
}
}
}