📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using Microsoft.Win32;
using CrystalDecisions.Shared;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Test test = new Test();
Tests tests = new Tests();
test.Name = this.textBox1.Text;
test.TotalMenoy = 2.347M;
tests.Add(test);
Print(tests, 5, 0, 5, 0);
}
private void Print(Tests PrintToFPs, int Left, int Right, int Top, int Bottom)
{
ReportDocument Document = new ReportDocument();
//读取安装路径
string Path = Environment.CurrentDirectory;
//Path = Path.Substring(0, Path.Length - 11);
Path = Path + @"\CrystalReport1.rpt";
Document.Load(Path);
Document.SetDataSource(PrintToFPs);
//ReportDocument SubDocument = Document.Subreports["InvoiceDetail.rpt"];
//SubDocument.SetDataSource(PrintHospitalCharges);
PageMargins pageMargins = Document.PrintOptions.PageMargins;
pageMargins.leftMargin = Left;
pageMargins.rightMargin = Right;
pageMargins.topMargin = Top;
pageMargins.bottomMargin = Bottom;
Document.PrintOptions.ApplyPageMargins(pageMargins);
try
{
Document.PrintToPrinter(10,false, 0, 0);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -