Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Why the picture not save correctly if I change from button click to form load

Why the picture not save correctly if I change from button click to form load

Scheduled Pinned Locked Moved Visual Basic
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Munirah Malik
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • M Munirah Malik

      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

      P Offline
      P Offline
      Peter Leow
      wrote on last edited by
      #2

      vb6. What nostalgia. Try

      Private Sub Command1_Click(index As Integer)

      Call Command1_Click(0)

      Peter Leow http://www.peterleowblog.com/ https://www.amazon.com/author/peterleow

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups