📄 frmdemo.frm
字号:
End
Attribute VB_Name = "frmDemo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'/****************************************************************************
' 我为人人,人人为我!
' 枕善居收集汉化整理
' http://www.mndsoft.com/blog/
' e-mail:mnd@mndsoft.com
' ****************************************************************************/
Option Explicit
'The dimensions of the DIN A4 paper size in Twips:
Const A4Height = 16840, A4Width = 11907
'To get the scroll width:
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CYHSCROLL = 3
Private Const SM_CXVSCROLL = 2
'Declared Private WithEvents to get NewPage event:
Private WithEvents cTP As clsTablePrint
Attribute cTP.VB_VarHelpID = -1
Private Sub FillListView()
Dim lCol As Long, lRow As Long, LI As ListItem
For lRow = 1 To 100
Set LI = lvData.ListItems.Add(, , "Row " & lRow & ", First Column", , 1)
For lCol = 1 To lvData.ColumnHeaders.Count - 1
LI.SubItems(lCol) = "Row " & CStr(lRow) & ", Col " & CStr(lCol + 1)
Next
Next
End Sub
Private Sub InitializePictureBox()
Dim sngVSCWidth As Single, sngHSCHeight As Single
'Set the size to the DIN A4 width:
picTarget.Width = A4Width
picTarget.Height = A4Height
'Resize the scrollbars:
sngVSCWidth = GetSystemMetrics(SM_CXVSCROLL) * Screen.TwipsPerPixelX
sngHSCHeight = GetSystemMetrics(SM_CYHSCROLL) * Screen.TwipsPerPixelY
hscScroll.Move 0, picScroll.ScaleHeight - sngHSCHeight, picScroll.ScaleWidth - sngVSCWidth, sngHSCHeight
vscScroll.Move picScroll.ScaleWidth - sngVSCWidth, 0, sngVSCWidth, picScroll.ScaleHeight
SetScrollBars
End Sub
Private Sub SetScrollBars()
hscScroll.Max = (picTarget.Width - picScroll.ScaleWidth + vscScroll.Width) / 120 + 1
vscScroll.Max = (picTarget.Height - picScroll.ScaleHeight + hscScroll.Height) / 120 + 1
End Sub
Private Sub Check1_Click()
cmdRefresh1_Click
End Sub
Private Sub chkColWidth_Click()
cmdRefresh_Click
End Sub
Private Sub chkIcons_Click()
cmdRefresh_Click
End Sub
Private Sub CmdFlexPnt_Click()
cmdRefresh1_Click
End Sub
Private Sub CmdListPnt_Click()
cmdRefresh_Click
End Sub
Private Sub cmdPrint_Click()
If MsgBox("The application will now print the grid on the default printer (Show a print dialog here later !).", vbInformation + vbOKCancel, "Print") = vbCancel Then Exit Sub
'Simply initialize the printer:
Printer.Print
'Read the FlexGrid:
'Set the wanted width of the table to -1 to get the exact widths of the FlexGrid,
' to ScaleWidth - [the left and right margins] to get a fitting table !
ImportFlexGrid cTP, fxgSrc, IIf((chkColWidth.Value = vbChecked), Printer.ScaleWidth - 2 * 567, -1)
'Set margins (not needed, but looks better !):
cTP.MarginBottom = 567 '567 equals to 1 cm
cTP.MarginLeft = 567
cTP.MarginTop = 567
'Class begins drawing at CurrentY !
Printer.CurrentY = cTP.MarginTop
'Finally draw the Grid !
cTP.DrawTable Printer
'Done with drawing !
'Say VB it should finally send it:
Printer.EndDoc
End Sub
Private Sub cmdRefresh_Click()
'Read the ListView:
'Set the wanted width of the table to -1 to get the exact widths of the FlexGrid,
' to ScaleWidth - [the left and right margins] to get a fitting table !
ImportListView cTP, lvData, IIf((chkColWidth.Value = vbChecked), picTarget.ScaleWidth - 2 * 567, -1), chkIcons.Value
'Here you can set RowHeightMin and HeaderRowMinHeight if the rows are too small:
' cTP.RowHeightMin = 180
' cTP.HeaderRowHeightMin = cTP.RowHeightMin
'Set margins (not needed, but looks better !):
cTP.MarginBottom = 567 '567 equals to 1 cm
cTP.MarginLeft = 567
cTP.MarginTop = 567
'Clear the box:
picTarget.Cls
'Class begins drawing at CurrentY !
picTarget.CurrentY = cTP.MarginTop
'Finally draw the Grid !
cTP.DrawTable picTarget
'Done with drawing !
End Sub
Private Sub cmdRefresh1_Click()
'Read the ListView:
'Set the wanted width of the table to -1 to get the exact widths of the FlexGrid,
' to ScaleWidth - [the left and right margins] to get a fitting table !
' ImportListView cTP, MSFlexGrid1, IIf((chkColWidth.Value = vbChecked), picTarget.ScaleWidth - 2 * 567, -1), chkIcons.Value
ImportGrid cTP, MSFlexGrid1, IIf((chkColWidth.Value = vbChecked), picTarget.ScaleWidth - 2 * 567, -1)
'Here you can set RowHeightMin and HeaderRowMinHeight if the rows are too small:
' cTP.RowHeightMin = 180
' cTP.HeaderRowHeightMin = cTP.RowHeightMin
'Set margins (not needed, but looks better !):
cTP.MarginBottom = 567 '567 equals to 1 cm
cTP.MarginLeft = 567
cTP.MarginTop = 567
'Clear the box:
picTarget.Cls
'Class begins drawing at CurrentY !
picTarget.CurrentY = cTP.MarginTop
'Finally draw the Grid !
cTP.DrawTable picTarget
'Done with drawing !
End Sub
Private Sub cTP_NewPage(objOutput As Object, TopMarginAlreadySet As Boolean, bCancel As Boolean, ByVal lLastPrintedRow As Long)
'The class wants a new page, look what to do
If TypeOf objOutput Is Printer Then
Printer.NewPage
Else 'We are printing on the PictureBox !
objOutput.CurrentY = objOutput.ScaleHeight
'Simply increase the height of the PicBox here
' (very simple, but looks bad in "real" applications)
objOutput.Height = objOutput.Height + A4Height
'Draw a line to show the new page:
objOutput.Line (0, objOutput.CurrentY)-(objOutput.ScaleWidth, objOutput.CurrentY), &H808080
'Set the CurrentY to the position the class should continie with drawing and...
objOutput.CurrentY = objOutput.CurrentY + cTP.MarginTop
'... tell it to do so:
TopMarginAlreadySet = True
'Set the ScrollBar Max properties:
SetScrollBars
End If
End Sub
Private Sub Form_Load()
InitializePictureBox
FillListView
InitGrid
Set cTP = New clsTablePrint
'cmdRefresh_Click
End Sub
Private Sub hscScroll_Change()
picTarget.Left = -hscScroll.Value * 120
End Sub
Private Sub hscScroll_Scroll()
hscScroll_Change
End Sub
Private Sub vscScroll_Change()
picTarget.Top = -vscScroll.Value * 120
End Sub
Private Sub vscScroll_Scroll()
vscScroll_Change
End Sub
Private Sub InitGrid()
Dim i As Integer
Dim j As Integer
Dim k As Integer
k = 0
With MSFlexGrid1
.Rows = 11
.Cols = 11
.ColWidth(0) = 300
For i = 1 To 10
.Row = i
For j = 1 To 10
.Col = j
.ColWidth(i) = 500
k = k + 1
.Text = k
.CellAlignment = flexAlignCenterCenter
Next
Next
.Col = 0
For i = 1 To 10
.Row = i
.Text = i
Next
.Row = 0
For i = 1 To 10
.Col = i
.Text = i
.CellAlignment = flexAlignCenterCenter
Next
End With
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -