📄 main.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BackColor = &H8000000A&
Caption = "打印窗体"
ClientHeight = 4425
ClientLeft = 165
ClientTop = 735
ClientWidth = 5850
LinkTopic = "Form1"
ScaleHeight = 4425
ScaleWidth = 5850
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdPrint
Caption = "打印"
Height = 495
Left = 480
TabIndex = 1
Top = 1320
Width = 1215
End
Begin VB.PictureBox picPrint
BorderStyle = 0 'None
Height = 855
Left = 2640
ScaleHeight = 855
ScaleWidth = 855
TabIndex = 0
Top = 2880
Visible = 0 'False
Width = 855
End
Begin VB.Line Line2
X1 = 2160
X2 = 4800
Y1 = 2400
Y2 = 480
End
Begin VB.Line Line1
X1 = 2400
X2 = 4680
Y1 = 600
Y2 = 2040
End
Begin VB.Menu mPercentPrint
Caption = "打印比例"
Begin VB.Menu mPercent
Caption = "50%"
Index = 50
End
Begin VB.Menu mPercent
Caption = "100%"
Index = 100
End
Begin VB.Menu mPercent
Caption = "150%"
Index = 150
End
Begin VB.Menu mPercent
Caption = "200%"
Index = 200
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc _
As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) _
As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, _
ByVal hDC As Long) As Long
Dim N As Long
Private Sub cmdPrint_Click()
Dim sx As Long, sy As Long, hDC As Long
Dim px As Long, py As Long, I As Integer
Me.ScaleMode = vbPixels
sx = Me.Width / Screen.TwipsPerPixelX
sy = Me.Height / Screen.TwipsPerPixelY
picPrint.Width = sx
picPrint.Height = sy
For I = 0 To Controls.Count - 1
If TypeName(Controls(I)) <> "Menu" Then Controls(I).Visible = False
Next
DoEvents
picPrint.AutoRedraw = True
hDC = GetWindowDC(Me.hWnd)
BitBlt picPrint.hDC, 0, 0, sx, sy, hDC, 0, 0, vbSrcCopy
ReleaseDC Me.hWnd, hDC
picPrint.AutoRedraw = False
For I = 0 To Controls.Count - 1
If TypeName(Controls(I)) <> "Menu" And _
Controls(I).Name <> "picPrint" Then Controls(I).Visible = True
Next
Set picPrint.Picture = picPrint.Image
Dim w As Long, h As Long
Me.ScaleMode = vbTwips
Printer.ScaleMode = vbTwips
w = picPrint.Width * N \ 100
h = picPrint.Height * N \ 100
px = (Printer.ScaleWidth - w) / 2
py = (Printer.ScaleHeight - h) / 2
Printer.PaintPicture picPrint.Picture, px, py, w, h
Printer.EndDoc
End Sub
Private Sub Form_Load()
mPercent(100).Checked = True
N = 100
End Sub
Private Sub mPercent_Click(Index As Integer)
mPercent(50).Checked = False
mPercent(100).Checked = False
mPercent(150).Checked = False
mPercent(200).Checked = False
mPercent(Index).Checked = True
N = Index
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -