質問編集履歴
1
きれいに印刷できるパターンのソースを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -39,6 +39,23 @@
|
|
39
39
|
task.Start()
|
40
40
|
End Sub
|
41
41
|
|
42
|
+
|
43
|
+
Private Const SRCCOPY As Integer = &HCC0020
|
44
|
+
'フォームのイメージを取得する
|
45
|
+
Public Function CaptureControl(ByVal ctrl As Control) As Bitmap
|
46
|
+
Dim g As Graphics = ctrl.CreateGraphics()
|
47
|
+
Dim img As New Bitmap(ctrl.ClientRectangle.Width,
|
48
|
+
ctrl.ClientRectangle.Height, g)
|
49
|
+
Dim memg As Graphics = Graphics.FromImage(img)
|
50
|
+
Dim dc1 As IntPtr = g.GetHdc()
|
51
|
+
Dim dc2 As IntPtr = memg.GetHdc()
|
52
|
+
BitBlt(dc2, 0, 0, img.Width, img.Height, dc1, 0, 0, SRCCOPY)
|
53
|
+
g.ReleaseHdc(dc1)
|
54
|
+
memg.ReleaseHdc(dc2)
|
55
|
+
memg.Dispose()
|
56
|
+
g.Dispose()
|
57
|
+
Return img
|
58
|
+
End Function
|
42
59
|
|
43
60
|
|
44
61
|
'PrintDocument1のPrintPageイベントハンドラ
|
@@ -117,3 +134,68 @@
|
|
117
134
|
### 補足情報(FW/ツールのバージョンなど)
|
118
135
|
VisualStudio2019(Professional Edition)を使用して開発しています。
|
119
136
|
|
137
|
+
|
138
|
+
|
139
|
+
### きれいに印刷できるパターンのソース
|
140
|
+
|
141
|
+
Module Com_ParkFunc
|
142
|
+
Public memoryImage As Bitmap
|
143
|
+
Public Sub PubS_PrintParkTicket(ByVal strSrvNum As String)
|
144
|
+
Dim SecName As String
|
145
|
+
Dim KeyName As String
|
146
|
+
|
147
|
+
'' 駐車サービス票の印刷処理
|
148
|
+
FrmTicket2.Show() '★★★★★★★★★ ←フォームは見えないようにしたい
|
149
|
+
'' 各項目の設定
|
150
|
+
With FrmTicket2
|
151
|
+
.Label5.Text = "てすと"
|
152
|
+
.lblDate.Text = VB6.Format(Now, "yyyy年mm月dd日 hh時nn分")
|
153
|
+
.lblSrvNo.Text = "12345678901234"
|
154
|
+
End With
|
155
|
+
MsgBox("print")'★★★★★★★★★ ←FrmTicket2.Refresh()でも印刷できました!!
|
156
|
+
memoryImage = CaptureControl(FrmTicket2)
|
157
|
+
Dim PrintDocument1 As New System.Drawing.Printing.PrintDocument
|
158
|
+
|
159
|
+
AddHandler PrintDocument1.PrintPage,
|
160
|
+
AddressOf PrintDocument1_PrintPage
|
161
|
+
|
162
|
+
PrintDocument1.Print()
|
163
|
+
memoryImage.Dispose()
|
164
|
+
|
165
|
+
'' フォームのアンロード
|
166
|
+
FrmTicket2.Hide()
|
167
|
+
End Sub
|
168
|
+
|
169
|
+
<System.Runtime.InteropServices.DllImport("gdi32.dll")>
|
170
|
+
Public Function BitBlt(ByVal hdcDest As IntPtr,
|
171
|
+
ByVal nXDest As Integer, ByVal nYDest As Integer,
|
172
|
+
ByVal nWidth As Integer, ByVal nHeight As Integer,
|
173
|
+
ByVal hdcSrc As IntPtr,
|
174
|
+
ByVal nXSrc As Integer, ByVal nYSrc As Integer,
|
175
|
+
ByVal dwRop As Integer) As Boolean
|
176
|
+
End Function
|
177
|
+
|
178
|
+
Private Const SRCCOPY As Integer = &HCC0020
|
179
|
+
'フォームのイメージを取得する
|
180
|
+
Public Function CaptureControl(ByVal ctrl As Control) As Bitmap
|
181
|
+
Dim g As Graphics = ctrl.CreateGraphics()
|
182
|
+
Dim img As New Bitmap(ctrl.ClientRectangle.Width,
|
183
|
+
ctrl.ClientRectangle.Height, g)
|
184
|
+
Dim memg As Graphics = Graphics.FromImage(img)
|
185
|
+
Dim dc1 As IntPtr = g.GetHdc()
|
186
|
+
Dim dc2 As IntPtr = memg.GetHdc()
|
187
|
+
BitBlt(dc2, 0, 0, img.Width, img.Height, dc1, 0, 0, SRCCOPY)
|
188
|
+
g.ReleaseHdc(dc1)
|
189
|
+
memg.ReleaseHdc(dc2)
|
190
|
+
memg.Dispose()
|
191
|
+
g.Dispose()
|
192
|
+
Return img
|
193
|
+
End Function
|
194
|
+
|
195
|
+
'PrintDocument1のPrintPageイベントハンドラ
|
196
|
+
Public Sub PrintDocument1_PrintPage(ByVal sender As Object,
|
197
|
+
ByVal e As System.Drawing.Printing.PrintPageEventArgs)
|
198
|
+
e.Graphics.DrawImage(memoryImage, 0, 0, 215, 325)
|
199
|
+
End Sub
|
200
|
+
End Module
|
201
|
+
|