📄 mainform.cs
字号:
this.pnlLeft.Name = "pnlLeft";
this.pnlLeft.Size = new System.Drawing.Size(200, 486);
this.pnlLeft.TabIndex = 0;
//
// tvNavigation
//
this.tvNavigation.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.tvNavigation.Dock = System.Windows.Forms.DockStyle.Fill;
this.tvNavigation.ImageIndex = -1;
this.tvNavigation.Location = new System.Drawing.Point(0, 0);
this.tvNavigation.Name = "tvNavigation";
this.tvNavigation.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Line Chart"),
new System.Windows.Forms.TreeNode("Column Chart"),
new System.Windows.Forms.TreeNode("Stacked Column Chart"),
new System.Windows.Forms.TreeNode("Bar Chart"),
new System.Windows.Forms.TreeNode("Stacked Bar Chart"),
new System.Windows.Forms.TreeNode("Area Chart"),
new System.Windows.Forms.TreeNode("Pie Chart"),
new System.Windows.Forms.TreeNode("Pie Exploded Chart"),
new System.Windows.Forms.TreeNode("Combination Chart")});
this.tvNavigation.SelectedImageIndex = -1;
this.tvNavigation.Size = new System.Drawing.Size(196, 482);
this.tvNavigation.TabIndex = 0;
this.tvNavigation.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvNavigation_AfterSelect);
//
// btnPdf
//
this.btnPdf.BackColor = System.Drawing.Color.Transparent;
this.btnPdf.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnPdf.Image = ((System.Drawing.Image)(resources.GetObject("btnPdf.Image")));
this.btnPdf.Location = new System.Drawing.Point(464, 16);
this.btnPdf.Name = "btnPdf";
this.btnPdf.Size = new System.Drawing.Size(44, 44);
this.btnPdf.TabIndex = 1;
this.btnPdf.Click += new System.EventHandler(this.btnPdf_Click);
//
// btnOriginalSize
//
this.btnOriginalSize.BackColor = System.Drawing.Color.Transparent;
this.btnOriginalSize.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnOriginalSize.Image = ((System.Drawing.Image)(resources.GetObject("btnOriginalSize.Image")));
this.btnOriginalSize.Location = new System.Drawing.Point(204, 16);
this.btnOriginalSize.Name = "btnOriginalSize";
this.btnOriginalSize.Size = new System.Drawing.Size(44, 44);
this.btnOriginalSize.TabIndex = 2;
this.btnOriginalSize.Click += new System.EventHandler(this.btnOriginalSize_Click);
//
// btnFullPage
//
this.btnFullPage.BackColor = System.Drawing.Color.Transparent;
this.btnFullPage.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnFullPage.Image = ((System.Drawing.Image)(resources.GetObject("btnFullPage.Image")));
this.btnFullPage.Location = new System.Drawing.Point(256, 16);
this.btnFullPage.Name = "btnFullPage";
this.btnFullPage.Size = new System.Drawing.Size(44, 44);
this.btnFullPage.TabIndex = 2;
this.btnFullPage.Click += new System.EventHandler(this.btnFullPage_Click);
//
// btnBestFit
//
this.btnBestFit.BackColor = System.Drawing.Color.Transparent;
this.btnBestFit.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnBestFit.Image = ((System.Drawing.Image)(resources.GetObject("btnBestFit.Image")));
this.btnBestFit.Location = new System.Drawing.Point(308, 16);
this.btnBestFit.Name = "btnBestFit";
this.btnBestFit.Size = new System.Drawing.Size(44, 44);
this.btnBestFit.TabIndex = 2;
this.btnBestFit.Click += new System.EventHandler(this.btnBestFit_Click);
//
// btnMinus
//
this.btnMinus.BackColor = System.Drawing.Color.Transparent;
this.btnMinus.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnMinus.Image = ((System.Drawing.Image)(resources.GetObject("btnMinus.Image")));
this.btnMinus.Location = new System.Drawing.Point(360, 16);
this.btnMinus.Name = "btnMinus";
this.btnMinus.Size = new System.Drawing.Size(44, 44);
this.btnMinus.TabIndex = 2;
this.btnMinus.Click += new System.EventHandler(this.btnMinus_Click);
//
// btnPlus
//
this.btnPlus.BackColor = System.Drawing.Color.Transparent;
this.btnPlus.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnPlus.Image = ((System.Drawing.Image)(resources.GetObject("btnPlus.Image")));
this.btnPlus.Location = new System.Drawing.Point(412, 16);
this.btnPlus.Name = "btnPlus";
this.btnPlus.Size = new System.Drawing.Size(44, 44);
this.btnPlus.TabIndex = 2;
this.btnPlus.Click += new System.EventHandler(this.btnPlus_Click);
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.WhiteSmoke;
this.ClientSize = new System.Drawing.Size(792, 566);
this.Controls.Add(this.btnOriginalSize);
this.Controls.Add(this.btnPdf);
this.Controls.Add(this.pnlMain);
this.Controls.Add(this.btnFullPage);
this.Controls.Add(this.btnBestFit);
this.Controls.Add(this.btnMinus);
this.Controls.Add(this.btnPlus);
this.DockPadding.Bottom = -2;
this.Name = "MainForm";
this.Text = "PDFsharp Charting Demo";
this.pnlMain.ResumeLayout(false);
this.pnlRight.ResumeLayout(false);
this.pnlPreview.ResumeLayout(false);
this.pnlLeft.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void tvNavigation_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
this.chartFrame = new ChartFrame();
this.chartFrame.Location = new XPoint(30, 30);
this.chartFrame.Size = new XSize(500, 600);
Chart chart = null;
switch (e.Node.Text.ToLower())
{
case "line chart":
chart = ChartSamples.LineChart();
break;
case "column chart":
chart = ChartSamples.ColumnChart();
break;
case "stacked column chart":
chart = ChartSamples.ColumnStackedChart();
break;
case "bar chart":
chart = ChartSamples.BarChart();
break;
case "stacked bar chart":
chart = ChartSamples.BarStackedChart();
break;
case "area chart":
chart = ChartSamples.AreaChart();
break;
case "pie chart":
chart = ChartSamples.PieChart();
break;
case "pie exploded chart":
chart = ChartSamples.PieExplodedChart();
break;
case "combination chart":
chart = ChartSamples.CombinationChart();
break;
}
this.chartFrame.Add(chart);
this.pagePreview.SetRenderEvent(new PagePreview.RenderEvent(chartFrame.Draw));
}
private void btnOriginalSize_Click(object sender, System.EventArgs e)
{
this.pagePreview.Zoom = Zoom.Percent100;
}
private void btnFullPage_Click(object sender, System.EventArgs e)
{
this.pagePreview.Zoom = Zoom.FullPage;
}
private void btnBestFit_Click(object sender, System.EventArgs e)
{
this.pagePreview.Zoom = Zoom.BestFit;
}
private void btnMinus_Click(object sender, System.EventArgs e)
{
this.pagePreview.ZoomPercent = GetNewZoom((int)this.pagePreview.ZoomPercent, false);
}
private void btnPlus_Click(object sender, System.EventArgs e)
{
this.pagePreview.ZoomPercent = GetNewZoom((int)this.pagePreview.ZoomPercent, true);
}
private void btnPdf_Click(object sender, System.EventArgs e)
{
string filename = Guid.NewGuid().ToString().ToUpper() + ".pdf";
PdfDocument document = new PdfDocument(filename);
PdfPage page = document.AddPage();
page.Size = PageSize.A4;
XGraphics gfx = XGraphics.FromPdfPage(page);
this.chartFrame.Draw(gfx);
document.Close();
Process.Start(filename);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -