Hi admin, I tried changed this code. I change the system save picture on form load not on button click. but the result, picture not save correctly. only blank picture. can we save the picture on form load? I use vb6
Private Sub Form_Load()
Call Command1_Click
End Sub
Private Sub Command1_Click()
SaveFormImageToFile frmSaveFormImageToFile, Picture1, "C:\Temp.bmp"
End Sub
Public Sub SaveFormImageToFile(ByRef ContainerForm As Form, ByRef PictureBoxControl As PictureBox, ByVal ImageFileName As String)
Dim FormInsideWidth As Long
Dim FormInsideHeight As Long
Dim PictureBoxLeft As Long
Dim PictureBoxTop As Long
Dim PictureBoxWidth As Long
Dim PictureBoxHeight As Long
Dim FormAutoRedrawValue As Boolean
With PictureBoxControl
'Set PictureBox properties
.Visible = False
.AutoRedraw = True
.Appearance = 0 ' Flat
.AutoSize = False
.BorderStyle = 0 'No border
'Store PictureBox Original Size and location Values
PictureBoxHeight = .Height: PictureBoxWidth = .Width: PictureBoxLeft = .Left: PictureBoxTop = .Top
'Make PictureBox to size to inside of form.
.Align = vbAlignTop: .Align = vbAlignLeft
DoEvents
FormInsideHeight = .Height: FormInsideWidth = .Width
'Restore PictureBox Original Size and location Values
.Align = vbAlignNone
.Height = FormInsideHeight: .Width = FormInsideWidth: .Left = PictureBoxLeft: .Top = PictureBoxTop
FormAutoRedrawValue = ContainerForm.AutoRedraw
ContainerForm.AutoRedraw = False
DoEvents
'Copy Form Image to Picture Box
BitBlt .hDC, 0, 0, FormInsideWidth / Screen.TwipsPerPixelX, FormInsideHeight / Screen.TwipsPerPixelY, ContainerForm.hDC, 0, 0, vbSrcCopy
DoEvents
SavePicture .Image, ImageFileName
DoEvents
ContainerForm.AutoRedraw = FormAutoRedrawValue
DoEvents
End With
End Sub