Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        myp.InvalidatePreview()
    End Sub

    Private Sub myp_PrintDocument() Handles myp.PrintDocument
        myp.IsNeedCheckNewPage = False
        myp.PageUnits = VBprinter.VB2008Print.PageExportUnit.CentiMeter
        '使用1/100厘米为计量单位
        myp.NewPage()

        MyDrawQJD()

        myp.Currenty = myp.PaperPrintHeight / 2
        Dim mypen As New Pen(Brushes.Black)
        mypen.DashStyle = Drawing2D.DashStyle.DashDot
        myp.DrawLine(mypen, New PointF(0, myp.Currenty), New PointF(myp.PaperPrintWidth, myp.Currenty))

        MyDrawQJD()
        '再打印联次信息
        Dim ss As String
        ss = "第一联：存根"
        myp.Currentx = myp.PaperPrintWidth + 20
        myp.Currenty = 0
        myp.DrawText(ss, 50, myp.PaperPrintHeight / 2, StringAlignment.Center, StringAlignment.Center, True, False, False, True, 6, 0)
        ss = "第二联：报销联"
        myp.Currentx = myp.PaperPrintWidth + 20
        myp.Currenty = myp.PaperPrintHeight / 2
        myp.DrawText(ss, 50, myp.PaperPrintHeight / 2, StringAlignment.Center, StringAlignment.Center, True, False, False, True, 6, 0)

    End Sub
    Private Sub MyDrawQJD()
        myp.Currenty = myp.Currenty + 50
        Dim font1 As Font = New Font("宋体", 10)
        Dim font2 As Font = New Font("华文行楷", 10, FontStyle.Bold)
        Dim myformat1 As New StringFormat(StringFormat.GenericTypographic)
        myformat1.LineAlignment = StringAlignment.Center
        myformat1.Alignment = StringAlignment.Near
        Dim myformat2 As New StringFormat(StringFormat.GenericTypographic)
        myformat2.LineAlignment = StringAlignment.Center
        myformat2.Alignment = StringAlignment.Center
        Dim myformat3 As New StringFormat(StringFormat.GenericTypographic)
        myformat3.LineAlignment = StringAlignment.Center
        myformat3.Alignment = StringAlignment.Far
        myp.DrawTitle("A单位请假单", New Font("黑体", 18, FontStyle.Bold), Color.Black, 0)
        Dim ss As String
        ss = "编号：" & "12345652"
        myp.DrawText(ss, myp.PaperPrintWidth, font1, Color.Black, myformat3, 0)
        Dim rowheight As Single
        rowheight = 60
        myp.NewRow(myp.LastDrawTextHeight)

        '表格第1行
        myp.DrawCell("姓名", 200, rowheight, font1, "2211", Color.Black, StringAlignment.Center, StringAlignment.Center)
        myp.DrawCell(TextBox1.Text, 250, rowheight, font1, "0211", Color.Black, StringAlignment.Center, StringAlignment.Center)
        myp.DrawCell("部门", 200, rowheight, font1, "0211", Color.Black, StringAlignment.Center, StringAlignment.Center)
        myp.DrawCell("财务部", 380, rowheight, font1, "0211", Color.Black, StringAlignment.Center, StringAlignment.Center)
        myp.DrawCell("职务", 200, rowheight, font1, "0211", Color.Black, StringAlignment.Center, StringAlignment.Center)
        myp.DrawCell("会计师", 380, rowheight, font1, "0221", Color.Black, StringAlignment.Center, StringAlignment.Center)
        Dim sumwidth As Single
        sumwidth = 200 + 250 + 200 + 380 + 200 + 380

        '表格第二行
        myp.NewRow(rowheight)
        Dim tempx As Single
        Dim tempy As Single
        tempx = myp.Currentx
        tempy = myp.Currenty
        rowheight = 60 * 2
        ss = "请假类别："
        myp.DrawCell(ss, sumwidth, rowheight, font1, "2021", Color.Black, StringAlignment.Near, StringAlignment.Center)
        Dim mywidth As Single
        mywidth = myp.MeasureText(ss, font1).Width

        Dim mycb As CheckBox = New CheckBox
        mycb.BackColor = Color.White
        mycb.Text = ""
        mycb.Checked = False
        myp.Currentx = tempx + mywidth
        myp.Currenty = tempy + 5
        myp.DrawCheckBox(mycb)
        myp.Currentx = myp.Currentx + 50
        ss = "公假（产假、婚假、护理假）"
        myp.Currenty = tempy + 10
        myp.DrawText(ss, font1, 0)
        myp.Currentx = myp.Currentx + 50
        mycb.Checked = True '假定是选 的是这个
        myp.Currenty = tempy + 5
        myp.DrawCheckBox(mycb)
        myp.Currentx = myp.Currentx + 50
        ss = "事假"
        myp.Currenty = tempy + 10
        myp.DrawText(ss, font1, 0)
        myp.Currentx = myp.Currentx + 50
        mycb.Checked = False
        myp.Currenty = tempy + 5
        myp.DrawCheckBox(mycb)
        myp.Currentx = myp.Currentx + 50
        ss = "病假（一般以上需医师证明）"
        myp.Currenty = tempy + 10
        myp.DrawText(ss, font1, 0)
        myp.Currentx = tempx + mywidth
        mycb.Checked = False
        myp.Currenty = tempy + rowheight / 2 - 5
        myp.DrawCheckBox(mycb)
        myp.Currentx = myp.Currentx + 50
        ss = "探亲假"
        myp.Currenty = tempy + rowheight / 2
        myp.DrawText(ss, font1, 0)
        mycb.Checked = False
        myp.Currenty = tempy + rowheight / 2 - 5
        myp.Currentx = myp.Currentx + 50

        myp.DrawCheckBox(mycb)
        myp.Currentx = myp.Currentx + 50
        ss = "其他（请说明）"
        myp.Currenty = tempy + rowheight / 2
        myp.DrawText(ss, font1, 0)

        myp.Currenty = tempy
        myp.Currentx = tempx
        myp.NewRow(rowheight)

        '表格第三行，分三行打印
        rowheight = 50
        ss = "  请假事由说明："
        myp.DrawCell(ss, sumwidth, rowheight, font1, "2020", Color.Black, StringAlignment.Near, StringAlignment.Center)
        myp.NewRow(rowheight)
        rowheight = 150
        ss = "这是我要请假的具体原因，请批准"
        myp.DrawCell(ss, sumwidth, rowheight, font1, "2020", Color.Black, StringAlignment.Near, StringAlignment.Center)
        myp.NewRow(rowheight)
        rowheight = 50
        ss = "                          签字：" & "张三"
        myp.DrawCell(ss, sumwidth, rowheight, font1, "2020", Color.Black, StringAlignment.Center, StringAlignment.Center)
        myp.NewRow(rowheight)
        rowheight = 50
        ss = "                          2013年4月29日"
        myp.DrawCell(ss, sumwidth, rowheight, font1, "2021", Color.Black, StringAlignment.Center, StringAlignment.Center)
        myp.NewRow(rowheight)

        '表格第四行打印
        rowheight = 50
        ss = "请假时间，从　年　月　日　到　　年　　月　日　共　　天"
        myp.DrawCell(ss, sumwidth, rowheight, font1, "2021", Color.Black, StringAlignment.Center, StringAlignment.Center)
        myp.NewRow(rowheight)

        '第五行
        rowheight = 50
        ss = "休假期间联系方式：" & "213434324"
        myp.DrawCell(ss, sumwidth / 2, rowheight, font1, "2011", Color.Black, StringAlignment.Near, StringAlignment.Center)
        ss = "休假期间应急委托人：" & "李四"
        myp.DrawCell(ss, sumwidth / 2, rowheight, font1, "0021", Color.Black, StringAlignment.Near, StringAlignment.Center)
        myp.NewRow(rowheight)

        '第六行,分三行打印

        rowheight = 50
        ss = "部门主管（经理）意见："
        myp.DrawCell(ss, sumwidth / 2, rowheight, font1, "2010", Color.Black, StringAlignment.Near, StringAlignment.Center)
        ss = "人力资源部（行政办）意见："
        myp.DrawCell(ss, sumwidth / 2, rowheight, font1, "2020", Color.Black, StringAlignment.Near, StringAlignment.Center)
        myp.NewRow(rowheight)
        rowheight = 100
        ss = "这是部门主管的意见，同意休假"
        myp.DrawCell(ss, sumwidth / 2, rowheight, font1, "2010", Color.Black, StringAlignment.Near, StringAlignment.Center)
        ss = "这是人力资源部的意见"
        myp.DrawCell(ss, sumwidth / 2, rowheight, font1, "2020", Color.Black, StringAlignment.Near, StringAlignment.Center)
        myp.NewRow(rowheight)
        rowheight = 50
        ss = "负责人：" & "麻六"
        myp.DrawCell(ss, sumwidth / 2, rowheight, font1, "2010", Color.Black, StringAlignment.Center, StringAlignment.Center)
        ss = "负责人：" & "人力主管"
        myp.DrawCell(ss, sumwidth / 2, rowheight, font1, "2020", Color.Black, StringAlignment.Center, StringAlignment.Center)
        myp.NewRow(rowheight)
        rowheight = 50
        ss = "  年　　月　　日"
        myp.DrawCell(ss, sumwidth / 2, rowheight, font1, "2011", Color.Black, StringAlignment.Center, StringAlignment.Center)
        ss = "  年　　月　　日"
        myp.DrawCell(ss, sumwidth / 2, rowheight, font1, "2021", Color.Black, StringAlignment.Center, StringAlignment.Center)
        myp.NewRow(rowheight)

        '第七行,采用简单的办法打印第7行
        rowheight = 250
        ss = "总经理意见：" & vbCrLf & vbCrLf & vbCrLf & "　　　　　　　　　　　总经理签字：" & vbCrLf & "　　　　　　　　　　　年    月   日"
        myp.DrawCell(ss, sumwidth / 2, rowheight, font1, "2012", Color.Black, StringAlignment.Near, StringAlignment.Center)

        Dim thewidth As Single = 50
        myp.DrawCell("说明", thewidth, rowheight, "0012", Color.Black, StringAlignment.Center, StringAlignment.Center, True, False, False, True, 0, 0)
        ss = "1、返回公司时间为销假时间" & vbCrLf & "2、所有员工3天以上请假需要总经理批准" & vbCrLf & "3、本表存人力资源部备案"
        myp.DrawCell(ss, sumwidth / 2 - thewidth, rowheight, font1, "0022", Color.Black, StringAlignment.Near, StringAlignment.Center)
        myp.NewRow(rowheight)

    End Sub

    Private Sub myp_QueryDefaultPageSettings(ByRef mypapesize As System.Drawing.Printing.PaperSize, ByRef thePaperMargin As System.Drawing.Printing.Margins, ByRef isPaperLandscape As System.Boolean) Handles myp.QueryDefaultPageSettings
        mypapesize = New System.Drawing.Printing.PaperSize("A4", 0, 0) '默认使用A4纸

    End Sub
End Class
