Results 1 to 3 of 3

Thread: [RESOLVED] Problem with form capture

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    9

    Resolved [RESOLVED] Problem with form capture

    I am having trouble with a screen save. Basically this part of code modifies some labels and pictures, takes a screen capture of the Form2 and places the screen capture image into picFrmMain. The issue is (I think) in FunQuestionOne, as you can see I change the labels around and then call the function GetFormImage but for some reason when I get the image it is without any of the changes to the label. I have a button that calls GetFormImage and it works fine but for some reason FunQuestionOne seems to be initiating the GetFormImage function before the labels are finished.

    Any suggestions?

    Thanks,

    Code:
    ‘In Form2 code
        Private Sub FunQuestionOne()
            picYes.Visible = False
            picNo.Visible = False
            lbltQuestion.Visible = True
    
            lblQuestion.Text = "MAIN QUESTION:..."
            editbuttoncontrols(pic1, 3, 1, 8)
            editlabelcontrols(lbl1, "ANSWER1", 20, 2, 4, 9)
    
            editbuttoncontrols(pic2, 3, 1, 12)
            editlabelcontrols(lbl2, "ANSWER2", 20, 2, 4, 13)
    
    
            frmMain.GetFormImage()
        End Sub
    
    ‘In form1
    Public Sub GetFormImage()
            Dim g As Graphics = SecondForm.CreateGraphics()
            Dim s As Size = SecondForm.Size
            formImage = New Bitmap(s.Width, s.Height, g)
            Dim mg As Graphics = Graphics.FromImage(formImage)
            Dim dc1 As IntPtr = g.GetHdc
            Dim dc2 As IntPtr = mg.GetHdc
            ' added code to compute and capture the form 
            ' title bar and borders 
            Dim widthDiff As Integer = _
               (SecondForm.Width - SecondForm.ClientRectangle.Width)
            Dim heightDiff As Integer = _
               (SecondForm.Height - SecondForm.ClientRectangle.Height)
            Dim borderSize As Integer = 0 'widthDiff \ 2
            Dim heightTitleBar As Integer = heightDiff - borderSize
            BitBlt(dc2, 0, 0, _
               SecondForm.ClientRectangle.Width + widthDiff, _
               SecondForm.ClientRectangle.Height + heightDiff, dc1, _
               0 - borderSize, 0 - heightTitleBar, 13369376)
    
            g.ReleaseHdc(dc1)
            mg.ReleaseHdc(dc2)
    
    
            picFrmMain.Image = New System.Drawing.Bitmap(formImage)
        End Sub

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Problem with form capture

    Hi boogieoompa,

    It might help to put Me.Refresh after editing the labels and before capturing the form. That makes sure any changes to the controls are painted before you capture it.

    By the way, if you are using VB2005 or later, you could use the Form.DrawToBitmap method to get a snapshot of the form. It captures the form complete with controls and border. For example:
    vb.net Code:
    1. Private Sub GetFormImage()
    2.    Dim bmp As New Bitmap(SecondForm.Width, SecondForm.Height)
    3.    SecondForm.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))
    4.    picFrmMain.Image = bmp
    5. End Sub

    all the best, BB

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    9

    Re: Problem with form capture

    Thanks a bunch the refresh thing worked :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width