[TrueChart for Windows Forms] ChartAreaのLocationDefaultとSizeDefaultを設定すると、印刷/プレビュー時にグラフ領域が正しい位置とサイズで描画されない
対象製品
ComponentOne Studio 2011J
状況
新バージョンで修正済み
詳細
ChartAreaのLocationDefaultとSizeDefaultを設定した場合、PrintDocumentクラスのPrintPageイベント内でC1ChartのDrawメソッドを呼び出すと、ChartAreaが本来の位置とサイズで描画されず、不正になります。
申し訳ございませんが、この不具合は本バージョンでは修正されません。
◎ComponentOne Studio 2012Jシリーズのサービスパックについて
http://www.grapecity.com/tools/support/salesend.htm#c1sp
申し訳ございませんが、この不具合は本バージョンでは修正されません。
◎ComponentOne Studio 2012Jシリーズのサービスパックについて
http://www.grapecity.com/tools/support/salesend.htm#c1sp
回避方法
PrintPageイベントでグラフ領域を表すGraphicsオブジェクト取得し、その原点に対して平行移動することで、ChartAreaを正しい位置に配置してください。
◆サンプルコード
-----------------
private void Form1_Load(object sender, EventArgs e)
{
c1Chart1.ChartArea.LocationDefault = defaultLocation;
c1Chart1.ChartArea.SizeDefault = defaultSize;
}
private void button1_Click(object sender, EventArgs e)
{
// PrintDocumentの生成
PrintDocument pd = new PrintDocument();
PrinterSettings ps = pd.PrinterSettings;
PaperSize indexA4 = null;
foreach (PaperSize temp in ps.PaperSizes)
{
if (temp.Kind == PaperKind.A4) indexA4 = temp;
}
pd.DefaultPageSettings.PaperSize = indexA4;
pd.DefaultPageSettings.Landscape = true;
pd.DefaultPageSettings.Margins.Top = 20;
pd.DefaultPageSettings.Margins.Left = 20;
pd.DefaultPageSettings.Margins.Bottom = 20;
pd.DefaultPageSettings.Margins.Right = 20;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// プレビュー画面の表示
PrintPreviewDialog ppDialog = new PrintPreviewDialog();
ppDialog.Document = pd;
ppDialog.ShowDialog();
}
private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
// グラフの描画
int x = e.MarginBounds.Left;
int y = e.MarginBounds.Top;
int width = e.MarginBounds.Width;
int height = e.MarginBounds.Height / 3;
Graphics g = e.Graphics;
System.Drawing.Drawing2D.GraphicsState gs = g.Save();
g.TranslateTransform(x, y);
c1Chart1.Draw(g, new Rectangle(0, 0, width, Height));
g.Restore(gs);
}
◆サンプルコード
-----------------
private void Form1_Load(object sender, EventArgs e)
{
c1Chart1.ChartArea.LocationDefault = defaultLocation;
c1Chart1.ChartArea.SizeDefault = defaultSize;
}
private void button1_Click(object sender, EventArgs e)
{
// PrintDocumentの生成
PrintDocument pd = new PrintDocument();
PrinterSettings ps = pd.PrinterSettings;
PaperSize indexA4 = null;
foreach (PaperSize temp in ps.PaperSizes)
{
if (temp.Kind == PaperKind.A4) indexA4 = temp;
}
pd.DefaultPageSettings.PaperSize = indexA4;
pd.DefaultPageSettings.Landscape = true;
pd.DefaultPageSettings.Margins.Top = 20;
pd.DefaultPageSettings.Margins.Left = 20;
pd.DefaultPageSettings.Margins.Bottom = 20;
pd.DefaultPageSettings.Margins.Right = 20;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// プレビュー画面の表示
PrintPreviewDialog ppDialog = new PrintPreviewDialog();
ppDialog.Document = pd;
ppDialog.ShowDialog();
}
private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
// グラフの描画
int x = e.MarginBounds.Left;
int y = e.MarginBounds.Top;
int width = e.MarginBounds.Width;
int height = e.MarginBounds.Height / 3;
Graphics g = e.Graphics;
System.Drawing.Drawing2D.GraphicsState gs = g.Save();
g.TranslateTransform(x, y);
c1Chart1.Draw(g, new Rectangle(0, 0, width, Height));
g.Restore(gs);
}