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;

namespace 会客单打印
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            myp.InvalidatePreview();
        }

        private void myp_PrintDocument()
        {
            myp.IsUseAPIprintDialog = true;
            StringFormat myformat = new StringFormat(StringFormat.GenericTypographic);
            myformat.Alignment = StringAlignment.Center;
            myformat.LineAlignment = StringAlignment.Center;
            myp.PageUnits =VBprinter .VB2008Print .PageExportUnit .CentiMeter ;
            int paperwidth ;
            int paperheight;
            String ss;
            RectangleF myrect;
            Font titlefont=new Font("黑体",12,FontStyle .Bold );
            Font txtfont1=new Font("宋体",9);
            Font txtfont2=new Font("隶书",9);
            float mywidth;
            paperwidth=Convert.ToInt32( myp.ConvertMmToInch (56)*100);
            paperheight=Convert.ToInt32( myp.ConvertMmToInch (70)*100);
            float colwidth1 = 100 ;
            float colwidth2 = 250;
            float colwidth3 = 80 ;
            float colwidth4 = 120;
            float rowheight ;
            float titleheight;
            titleheight = 40;
            rowheight=35;
            myp.NewDoc();
            myp.NewPage(new System.Drawing.Printing.PaperSize("会客凭证",paperwidth,paperheight),new System.Drawing.Printing .Margins (5,5,30,30));
            ss = "会 客 凭 证";
            myrect = new RectangleF(0, 0, myp.PaperPrintWidth, titleheight);
            myp.DrawTitle(ss,myrect, titlefont, Color.Blue,5,0);
            myp.NewRow(myp.LastDrawTextHeight/3);

            ss="访客等级：";
            myp.DrawText(ss, colwidth1, rowheight, txtfont1, StringAlignment.Near, StringAlignment.Center, false, false, false, false, 6, 0);
            ss = textBox1.Text;
            mywidth = myp.MeasureText(ss, txtfont2).Width;
            myp.DrawText(ss, mywidth, rowheight,txtfont2,StringAlignment.Near, StringAlignment.Center, false, false, false, false, 6, 0);
            myp.NewRow(rowheight );

            ss = "来访时间：";
           myp.DrawText(ss, colwidth1, rowheight, txtfont1, StringAlignment.Near, StringAlignment.Center, false, false, false, false, 6, 0);
            ss = textBox2.Text;
            mywidth = myp.MeasureText(ss, txtfont2).Width;
            myp.DrawText(ss, mywidth, rowheight, txtfont2, StringAlignment.Near, StringAlignment.Center, false, false, false, false, 6, 0);
            myp.NewRow(rowheight );

            ss = "访客姓名";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth1, rowheight);
            myp.DrawCell(ss, myrect, txtfont1,Color.Black,myformat,"1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth2, rowheight);
            ss = textBox3.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black,myformat,"1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth3+colwidth4, rowheight*6);
            myp.DrawCellImage(pictureBox1.Image, myrect.X, myrect.Y, myrect.Width, myrect.Height, "1111", true, StringAlignment.Center, StringAlignment.Center);
            myp.NewRow(rowheight);

            ss = "性别";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth1, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth2, rowheight);
            ss = textBox4.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myp.NewRow(rowheight);

            ss = "证件类型";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth1, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth2, rowheight);
            ss = textBox5.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myp.NewRow(rowheight);

            ss = "被访部门";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth1, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth2, rowheight);
            ss = textBox6.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myp.NewRow(rowheight);

            ss = "被访人姓名";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth1, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth2, rowheight);
            ss = textBox7.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myp.NewRow(rowheight);

            ss = "房间号";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth1, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth2, rowheight);
            ss = textBox8.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myp.NewRow(rowheight);


            ss = "来访人数";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth1, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth2, rowheight);
            ss = textBox9.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
            ss = "来访事由";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth3, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth4, rowheight);
            ss = textBox10.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myp.NewRow(rowheight);

            ss = "证件号码";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth1, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth2+colwidth3+colwidth4, rowheight);
            ss = textBox11.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myp.NewRow(rowheight);

            ss = "单位名称";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth1, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth2 + colwidth3 + colwidth4, rowheight);
            ss = textBox12.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myp.NewRow(rowheight);

            ss = "联系电话";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth1, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth2 + colwidth3 + colwidth4, rowheight);
            ss = textBox13.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myp.NewRow(rowheight);

            ss = "车牌号码";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth1, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth2, rowheight);
            ss = textBox14.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
            ss = "所带物品";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth3, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth4, rowheight);
            ss = textBox15.Text;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myp.NewRow(rowheight);

            ss = "被访人签名";
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth1, rowheight);
            myp.DrawCell(ss, myrect, txtfont1, Color.Black, myformat, "1111", Color.Black, 5, 0);
            myrect = new RectangleF(myp.Currentx, myp.Currenty, colwidth2 + colwidth3 + colwidth4, rowheight);
            ss = "时      分";
            myformat.Alignment = StringAlignment.Far;
            myp.DrawCell(ss, myrect, txtfont2, Color.Black, myformat, "1111", Color.Black, 5, 0);
     
            myp.EndDoc();

        }
    }
}
