C#code
private void Print1_Click_1(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
Margins margin = new Margins(20,20,20,20);
pd.DefaultPageSettings.Margins = margin;
PaperSize pagesize = new PaperSize("First custom size",400,240);
pd.DefaultPageSettings.PaperSize = pagesize;
pd.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage);
try
{
//pd.Print();
this.printPreviewDialog1.Document = this.printDocument1;
this.printPreviewDialog1.ShowDialog();
}
catch
{
throw new UserEmployeeException("请检查是否已连接到打印机");
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString("天津农学院处方便签",new Font("宋体",12,FontStyle.Bold),Brushes.Black,180,11 );
e.Graphics.DrawLine(new Pen(Color.Black),0,40,500,40);
e.Graphics.DrawString("姓名:" + nameBox.Text,new Font("宋体",9),Brushes.Black,10, 50);
e.Graphics.DrawString("年龄:"+ageBox.Text,new Font("宋体",9),Brushes.Black,100,50);
e.Graphics.DrawString("性别:" + sexBox.Text, new Font("宋体", 9), Brushes.Black, 180, 50);
e.Graphics.DrawString("日期:" + DateTime.Now.ToString(), new Font("宋体", 9), Brushes.Black, 260, 50);
e.Graphics.DrawString("诊断:"+diagnoseBox.Text , new Font("宋体", 9), Brushes.Black, 10, 90);
e.Graphics.DrawString("地址:" + addressBox.Text, new Font("宋体", 9), Brushes.Black, 180, 90);
e.Graphics.DrawLine(new Pen(Color.Black), 0, 110, 500, 110);
e.Graphics.DrawString("Rp", new Font("宋体", 12,FontStyle.Bold), Brushes.Black, 10, 120);
e.Graphics.DrawString(imformationBox.Text, new Font("宋体", 9), Brushes.Black, 40, 100);
e.Graphics.DrawLine(new Pen(Color.Black), 0, 700, 500, 700);
e.Graphics.DrawRectangle(new Pen(Color.Black), 30, 720,80,50);
e.Graphics.DrawString("划价" , new Font("宋体", 12), Brushes.Black, 50, 735);
e.Graphics.DrawRectangle(new Pen(Color.Black), 110, 720,80,50);
e.Graphics.DrawString(costBox.Text, new Font("宋体", 12), Brushes.Black, 140, 715);
e.Graphics.DrawString("收费/n盖章", new Font("宋体", 14), Brushes.Black, 250, 725);
e.Graphics.DrawString("医生:"+doctorBox.Text, new Font("宋体", 10), Brushes.Black, 320, 725);
e.Graphics.DrawString("配药:" + matchBox.Text, new Font("宋体", 10), Brushes.Black, 320, 750);
e.Graphics.DrawLine(new Pen(Color.Black), 0, 800, 500, 800);
//e.MarginBounds
; }