⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comprint.vb

📁 Visual Basic Oracle数据库联接
💻 VB
字号:
Option Strict Off
Imports System.IO
Public Class CustomPrintDocument
    Inherits System.Drawing.Printing.PrintDocument
    Private dataToPrint As StreamReader

    Public Sub CustomPrintDocument(ByVal data As StreamReader)
        dataToPrint = data
    End Sub
    Protected Overrides Sub OnBeginPrint(ByVal e As System.Drawing.Printing.PrintEventArgs)
        MyBase.OnBeginPrint(e)
    End Sub

    Protected Overrides Sub OnEndPrint(ByVal e As System.Drawing.Printing.PrintEventArgs)
        MyBase.OnEndPrint(e)
    End Sub

    Protected Overrides Sub OnPrintPage(ByVal e As System.Drawing.Printing.PrintPageEventArgs)
        MyBase.OnPrintPage(e)
        e.Graphics.DrawString("this is a test", New Font("Arial", 24), Brushes.Black, 100, 100)
        e.HasMorePages = False
    End Sub

    Protected Overrides Sub OnQueryPageSettings(ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs)
        MyBase.OnQueryPageSettings(e)
    End Sub

End Class
Public Class MarginInfo
    Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
    Private _leftMargin As Single = 0
    Private _topMargin As Single = 0
    Private _rightMargin As Single = 0
    Private _bottomMargin As Single = 0
    Const HORZSIZE As Short = 4         ' Horizontal size in millimeters 
    Const VERTSIZE As Short = 6         ' Vertical size in millimeters 
    Const HORZRES As Short = 8          ' Horizontal width in pixels 
    Const VERTRES As Short = 10         'Vertical height in pixels
    Const PHYSICALOFFSETX As Short = 112 ' Physical Printable Area x margin 
    Const PHYSICALOFFSETY As Short = 113 ' Physical Printable Area y margin 
    ' Modified from code originally written by Ron Allen (Ron@us-src.com).
    Public Sub New(ByVal deviceHandle As Integer)
        MyBase.New()
        ' Non printable margin in pixels
        Dim offsetX As Single = Convert.ToSingle(GetDeviceCaps(deviceHandle, PHYSICALOFFSETX))
        Dim offsetY As Single = Convert.ToSingle(GetDeviceCaps(deviceHandle, PHYSICALOFFSETY))
        ' printable page size in pixels
        Dim resolutionX As Single = Convert.ToSingle(GetDeviceCaps(deviceHandle, HORZRES))
        Dim resolutionY As Single = Convert.ToSingle(GetDeviceCaps(deviceHandle, VERTRES))
        ' printable page size in current unit (in this case, converted to inches)
        Dim horizontalSize As Single = Convert.ToSingle(GetDeviceCaps(deviceHandle, HORZSIZE)) / 25.4
        Dim verticalSize As Single = Convert.ToSingle(GetDeviceCaps(deviceHandle, VERTSIZE)) / 25.4

        Dim pixelsPerInchX As Single = resolutionX / horizontalSize
        Dim pixelsPerInchY As Single = resolutionY / verticalSize

        _leftMargin = (offsetX / pixelsPerInchX) * 100.0
        _topMargin = (offsetY / pixelsPerInchX) * 100.0
        _bottomMargin = _topMargin + (verticalSize * 100.0)
        _rightMargin = _leftMargin + (horizontalSize * 100.0)

    End Sub
    Public ReadOnly Property Left() As Single
        Get
            Return _leftMargin
        End Get
    End Property

    Public ReadOnly Property Right() As Single
        Get
            Return _rightMargin
        End Get
    End Property
    Public ReadOnly Property Top() As Single
        Get
            Return _topMargin
        End Get
    End Property
    Public ReadOnly Property Bottom() As Single
        Get
            Return _bottomMargin
        End Get
    End Property
    Public Overrides Function ToString() As String
        Return "left=" + _leftMargin.ToString() + ", top=" + _topMargin.ToString() + ", right=" + _rightMargin.ToString() + ", bottom=" + _bottomMargin.ToString()
    End Function

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -