using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Text;
using System.Windows.Forms;
using Hippo;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SeriesList sList = new SeriesList();
sList.ChartType = ChartType.Column;
sList.AxisFactor.YAxis.IsShorterFigures = true;
Random r = new Random();
for(int i = 0; i < 3; i++)
{
Series sr = new Series();
sr.Name = "Brand" + i.ToString();
sr.UnAxisFactor.PieTypes = PieType.TwoDemention;
for(int x = 0; x < 4; x++)
{
SeriesItem item = new SeriesItem();
item.Name = "product" + x.ToString();
item.IsShowFigureText = true;
item.YValue = r.Next(999999);
sr.items.Add(item);
}
sList.SeriesCollection.Add(sr);
}
this.hHippoChart1.LegendBox.Location = LegendLocation.Top;
this.hHippoChart1.LegendBox.Header.NameLabel.Text = "product111";
this.hHippoChart1.LegendBox.Visible = true;
this.hHippoChart1.Titles.Label.Text = "2015년 상반기 제품별 판매 현황";
this.hHippoChart1.SeriesListDictionary.Add(sList);
this.hHippoChart1.DrawChart();
this.hHippoChart1.SaveImage(@"c:\\printimage.png", System.Drawing.Imaging.ImageFormat.Png);
}
private void button1_Click(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
PrintDialog printdlg = new PrintDialog();
PrintPreviewDialog printPrvDlg = new PrintPreviewDialog();
printPrvDlg.Document = pd;
printPrvDlg.ShowDialog();
printdlg.Document = pd;
if (printdlg.ShowDialog() == DialogResult.OK)
{
pd.Print();
}
}
void pd_PrintPage(object sender, PrintPageEventArgs e)
{
Single yPos = 0;
Single leftMargin = e.MarginBounds.Left;
Single topMargin = e.MarginBounds.Top;
Image img = Image.FromFile("c:\\printimage.png");
RectangleF chart;
using (Font printFont = new Font("Arial", 15))
{
yPos += 10;
e.Graphics.DrawString(this.hHippoChart1.Titles.Label.Text, printFont, Brushes.Black, 25, yPos, new StringFormat());
yPos += 50;
chart = new RectangleF(leftMargin - 35 + e.MarginBounds.Width / 2 - this.hHippoChart1.Width / 2, (int)yPos, this.hHippoChart1.Width, this.hHippoChart1.Height);
e.Graphics.DrawImage(img, chart.X, chart.Y, chart.Width, chart.Height);
}
yPos += this.hHippoChart1.Height + 50;
// 그리드
// 그리드 열 카운트
int hoCount = this.hHippoChart1.SeriesListDictionary[0].SeriesCollection.Count + 1;
// 그리드 행 카운트
int verCount = this.hHippoChart1.SeriesListDictionary[0].SeriesCollection[0].items.Count + 1;
int tempLeft = (int)(leftMargin - 35);
for(int i = 0; i < hoCount; i++)
{
RectangleF recCell = new RectangleF(tempLeft, yPos, 170, 50);
using (SolidBrush sol = new SolidBrush(Color.WhiteSmoke))
{
e.Graphics.FillRectangle(sol, recCell.X, recCell.Y, recCell.Width, recCell.Height);
}
using (Pen p = new Pen(Color.Gray))
{
e.Graphics.DrawRectangle(p, recCell.X, recCell.Y, recCell.Width, recCell.Height);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
using (Font printFont = new Font("굴림", 14))
{
if (i == 0)
{
e.Graphics.DrawString("Product/Brand", printFont, Brushes.Black, recCell, format);
}
else
{
e.Graphics.DrawString(this.hHippoChart1.SeriesListDictionary[0].SeriesCollection[i - 1].Name, printFont, Brushes.Black, recCell, format);
}
}
}
tempLeft += 170;
}
yPos += 50;
for(int j = 1; j < verCount; j++)
{
tempLeft = (int)(leftMargin - 35);
for(int i = 0; i < hoCount; i++)
{
using (Pen p = new Pen(Color.Gray))
{
RectangleF recCell2 = new RectangleF(tempLeft, yPos, 170, 50);
e.Graphics.DrawRectangle(p, recCell2.X, recCell2.Y, recCell2.Width, recCell2.Height);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Far;
format.LineAlignment = StringAlignment.Center;
using (Font printFont = new Font("굴림", 14))
{
if (i == 0)
{
format.Alignment = StringAlignment.Near;
e.Graphics.DrawString(this.hHippoChart1.SeriesListDictionary[0].SeriesCollection[0].items[j - 1].Name, printFont, Brushes.Black, recCell2, format);
}
else
{
e.Graphics.DrawString(this.hHippoChart1.SeriesListDictionary[0].SeriesCollection[i - 1].items[j - 1].YValue.ToString(), printFont, Brushes.Black, recCell2, format);
}
}
}
tempLeft += 170;
}
yPos += 50;
}
yPos += 50;
RectangleF rec = new RectangleF(leftMargin - 35, yPos, e.MarginBounds.Width + 70, 222);
using (Pen p = new Pen(Color.Gray))
{
//e.Graphics.DrawRectangle(p, rec.X, rec.Y, rec.Width, rec.Height);
using (Font printFont = new Font("굴림", 10))
{
e.Graphics.DrawString(this.textBox1.Text, printFont, Brushes.Black, rec);
}
}
}
}
}
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Text
Imports System.Windows.Forms
Imports Hippo
Namespace WindowsApplication3
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs)
Dim sList As New. SeriesList()
sList.ChartType = ChartType.Column
sList.AxisFactor.YAxis.IsShorterFigures = True
Dim r As New. Random()
For i As Integer = 0 To 2
Dim sr As New. Series()
sr.Name = "Brand" + i.ToString()
sr.UnAxisFactor.PieTypes = PieType.TwoDemention
For x As Integer = 0 To 3
Dim item As New. SeriesItem()
item.Name = "product" + x.ToString()
item.IsShowFigureText = True
item.YValue = r.[Next](999999)
sr.items.Add(item)
Next
sList.SeriesCollection.Add(sr)
Next
Me.hHippoChart1.LegendBox.Location = LegendLocation.Top
Me.hHippoChart1.LegendBox.Header.NameLabel.Text = "product111"
Me.hHippoChart1.LegendBox.Visible = True
Me.hHippoChart1.Titles.Label.Text = "2015년 상반기 제품별 판매 현황"
Me.hHippoChart1.SeriesListDictionary.Add(sList)
Me.hHippoChart1.DrawChart()
Me.hHippoChart1.SaveImage("c:\\printimage.png", System.Drawing.Imaging.ImageFormat.Png)
End Sub
Private Sub button1_Click(sender As Object, e As EventArgs)
Dim pd As New. PrintDocument()
pd.PrintPage += New PrintPageEventHandler(AddressOf Me.pd_PrintPage)
Dim printdlg As New. PrintDialog()
Dim printPrvDlg As New. PrintPreviewDialog()
printPrvDlg.Document = pd
printPrvDlg.ShowDialog()
printdlg.Document = pd
If printdlg.ShowDialog() = DialogResult.OK Then
pd.Print()
End If
End Sub
Private Sub pd_PrintPage(sender As Object, e As PrintPageEventArgs)
Dim yPos As [Single] = 0
Dim leftMargin As [Single] = e.MarginBounds.Left
Dim topMargin As [Single] = e.MarginBounds.Top
Dim img As Image = Image.FromFile("c:\printimage.png")
Dim chart As RectangleF
Using printFont As New. Font("Arial", 15)
yPos += 10
e.Graphics.DrawString(Me.hHippoChart1.Titles.Label.Text, printFont, Brushes.Black, 25, yPos, New StringFormat())
yPos += 50
chart = New RectangleF(leftMargin - 35 + e.MarginBounds.Width / 2 - Me.hHippoChart1.Width / 2, CInt(yPos), Me.hHippoChart1.Width, Me.hHippoChart1.Height)
e.Graphics.DrawImage(img, chart.X, chart.Y, chart.Width, chart.Height)
End Using
yPos += Me.hHippoChart1.Height + 50
` 그리드
` 그리드 열 카운트
Dim hoCount As Integer = Me.hHippoChart1.SeriesListDictionary(0).SeriesCollection.Count + 1
` 그리드 행 카운트
Dim verCount As Integer = Me.hHippoChart1.SeriesListDictionary(0).SeriesCollection(0).items.Count + 1
Dim tempLeft As Integer = CInt(leftMargin - 35)
For i As Integer = 0 To hoCount - 1
Dim recCell As New. RectangleF(tempLeft, yPos, 170, 50)
Using sol As New. SolidBrush(Color.WhiteSmoke)
e.Graphics.FillRectangle(sol, recCell.X, recCell.Y, recCell.Width, recCell.Height)
End Using
Using p As New. Pen(Color.Gray)
e.Graphics.DrawRectangle(p, recCell.X, recCell.Y, recCell.Width, recCell.Height)
Dim format As New. StringFormat()
format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
Using printFont As New. Font("굴림", 14)
If i = 0 Then
e.Graphics.DrawString("Product/Brand", printFont, Brushes.Black, recCell, format)
Else
e.Graphics.DrawString(Me.hHippoChart1.SeriesListDictionary(0).SeriesCollection(i - 1).Name, printFont, Brushes.Black, recCell, format)
End If
End Using
End Using
tempLeft += 170
Next
yPos += 50
For j As Integer = 1 To verCount - 1
tempLeft = CInt(leftMargin - 35)
For i As Integer = 0 To hoCount - 1
Using p As New. Pen(Color.Gray)
Dim recCell2 As New. RectangleF(tempLeft, yPos, 170, 50)
e.Graphics.DrawRectangle(p, recCell2.X, recCell2.Y, recCell2.Width, recCell2.Height)
Dim format As New. StringFormat()
format.Alignment = StringAlignment.Far
format.LineAlignment = StringAlignment.Center
Using printFont As New. Font("굴림", 14)
If i = 0 Then
format.Alignment = StringAlignment.Near
e.Graphics.DrawString(Me.hHippoChart1.SeriesListDictionary(0).SeriesCollection(0).items(j - 1).Name, printFont, Brushes.Black, recCell2, format)
Else
e.Graphics.DrawString(Me.hHippoChart1.SeriesListDictionary(0).SeriesCollection(i - 1).items(j - 1).YValue.ToString(), printFont, Brushes.Black, recCell2, format)
End If
End Using
End Using
tempLeft += 170
Next
yPos += 50
Next
yPos += 50
Dim rec As New. RectangleF(leftMargin - 35, yPos, e.MarginBounds.Width + 70, 222)
Using p As New. Pen(Color.Gray)
`e.Graphics.DrawRectangle(p, rec.X, rec.Y, rec.Width, rec.Height);
Using printFont As New. Font("굴림", 10)
e.Graphics.DrawString(Me.textBox1.Text, printFont, Brushes.Black, rec)
End Using
End Using
End Sub
End Class
End Namespace