DLL:
背景:
开始做中谷项目时我还不知道怎么用DLL。后来看别人用才试着去学习使用。虽然现在已经会用了,但DLL的强大之处我了解的还远远不够。下面先简单说下DLL。
DLL是神马?
Windows操作系统是非常依赖于动态链接库(DLL)中的函数和数据的,实际上操作系统中几乎所有的内容都由DLL以一种或另外一种形式代表着,例如显示的字体和图标存储在GDI DLL中、显示windows桌面和处理用户的输入所需要的代码被存储在一个User DLL中、Windows编程所需要的大量API函数也呗包含在Kernel DLL中。
使用DLL优点多多:
最主要的一点是多个应用程序、甚至不同语言编写的应用程序可以共享一个DLL文件,实现资源“共享”,这样就大大缩小了应用程序的执行代码,有效利用内存;另一个优点是DLL文件作为一个单独的程序模块,封装性、独立性好,在软件需要升级的时候,开发人员只需要修改相应的DLl文件就可以了,而且,当DLL中的函数改变后,只要不是参数的改变,程序代码并不需要重新编译,这在编程时大大提高了软件开发和维护的效率。
我要使用啦:
打印:
很多窗体都需要打印功能,为了调用方便,我把打印写成一个类封装成DLL,然后在程序里添加引用。Print类代码也附到这里,不是重点。
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Windows.Forms
Public Class Class1
Private PrintFont As New Font("宋体", 10)
Private PrintLines As Integer = 50
Private PrintRecordNumber As Integer = 45
Private DataGridSource As DataGridView
Private ev As PrintPageEventArgs
Private PrintDataGrid As PrintDocument
Private PrintPriview As PrintPreviewDialog
Private PageSetup As PageSetupDialog
Private PrintScale As Double = 1
Private DataGridColumn As DataColumn
Private DataGridRow As DataRow
Private DataGridTable As DataTable
Private Cols As Integer
Private Rows As Integer = 1
Private ColsCount As Integer
Private PrintingLineNumber As Integer = 0
Private PageRecordNumber As Integer
Dim X_unit As Integer
Dim Y_unit As Integer
Dim _strPrint As String
Private PrintingPageNumber As Integer = 0
Private PageNumber As Integer
Private PrintRecordLeave As Integer
Private PrintRecordComplete As Integer = 0
'''
''' 设置打印字体
'''
'''
'''
Public WriteOnly Property setPrintFont() As System.Drawing.Font
Set(ByVal Value As System.Drawing.Font)
PrintFont = Value
End Set
End Property
Public WriteOnly Property setPrintRecordNumber() As Integer
Set(ByVal Value As Integer)
PrintRecordNumber = Value
End Set
End Property
'''
''' 设置表头
'''
'''
'''
'''
Public Property setstrPrint() As String
Set(ByVal value As String)
_strPrint = value
End Set
Get
Return _strPrint
End Get
End Property
Sub New(ByVal TableSource As DataGridView)
DataGridSource = TableSource
DataGridTable = New DataTable
DataGridTable = DataGridSource.DataSource()
ColsCount = DataGridTable.Columns.Count
End Sub
Public Sub Print()
Try
PrintDataGrid = New System.Drawing.Printing.PrintDocument
AddHandler PrintDataGrid.PrintPage, AddressOf Me.PrintDataGrid_PrintPage
'*
PageSetup = New PageSetupDialog
PageSetup.PageSettings = PrintDataGrid.DefaultPageSettings
If PageSetup.ShowDialog() = DialogResult.Cancel Then
Exit Sub
End If
'*
If PrintDataGrid.DefaultPageSettings.Landscape = False Then
PrintLines = PrintDataGrid.DefaultPageSettings.PaperSize.Height / (PrintFont.Height + 5)
Else
PrintLines = PrintDataGrid.DefaultPageSettings.PaperSize.Width / (PrintFont.Height + 5)
End If
'*
If PrintDataGrid.DefaultPageSettings.PaperSize.PaperName.ToString = "custom" Then
End If
'*
PrintPriview = New PrintPreviewDialog
PrintPriview.Document = PrintDataGrid
PrintPriview.ShowDialog()
Catch ex As Exception
MessageBox.Show("错误:" & ex.ToString)
End Try
End Sub
Private Sub PrintDataGrid_PrintPage(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
Dim strPrint As String = Nothing
Dim DrawBrush As New SolidBrush(System.Drawing.Color.Blue)
Dim X As In