Results 1 to 6 of 6

Thread: [RESOLVED] Screen capture of a MDI children

  1. #1

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Resolved [RESOLVED] Screen capture of a MDI children

    All

    I am trying to get the screen capture of a MDI children form. Somehow it is just not working.

    Does anyone know where i am going where here?

    Cheers

    Ken

    Code:
       Private Sub btnScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScreen.Click
            Dim frmMain As frmParent = Me.MdiParent
    
    
            For Each ctl As Control In frmMain.MdiChildren
                If TypeOf ctl Is frmOverview Then
                    Dim frm As frmOverview = ctl
                    Dim MyBMP As New Bitmap(frm.Width, frm.Height)
                    Dim G As Graphics = Graphics.FromImage(MyBMP)
                    'copies image data at location of form (top left), width of the form, to get entire form contents
                    G.CopyFromScreen(New Point(frm.Location.X, frm.Location.Y), New Point(frm.Location.X, frm.Location.Y), New Size(frm.Width, frm.Height))
                    G.Dispose()
                    'saves the image
                    Clipboard.SetImage(MyBMP)
                    MessageBox.Show("Screen capture success!")
                    Exit Sub
                End If
            Next
    If you find my thread helpful, please remember to rate me

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Screen capture of a MDI children

    First thing I'd ask is "how is it not working"? You need to be a bit more descriptive in order for people to help you out.

    Is it giving you the message but not setting the image to the clipboard or are you not even get the message, or will it not even compile?

  3. #3

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Screen capture of a MDI children

    It is not copying the exact dimensions... it is copying abit of the MDI parent too...
    If you find my thread helpful, please remember to rate me

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Screen capture of a MDI children

    OK so that narrows it down to this line :

    Code:
    G.CopyFromScreen(New Point(frm.Location.X, frm.Location.Y), New Point(frm.Location.X, frm.Location.Y), New Size(frm.Width, frm.Height)
    I've never used the copyfromscreen method, but I'd immediately be a bit suspicious that the first two params are identical. Just a quick check suggests that the first should be the source top left position and the second the destination top left position. That suggests to me they shouldn't be identical necessarily.

    Is that where your problem lies?

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: Screen capture of a MDI children

    Try this:
    Code:
           For Each frm As Form In frmMain.MdiChildren
                Using bmp As New Bitmap(frm.Width, frm.Height)
                    frm.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))
                    'Now you have the child form image in bmp bitmap, do whatever desired with it
                    '
                End Using
            Next
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  6. #6

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Screen capture of a MDI children

    That worked a treat! Thanks!
    If you find my thread helpful, please remember to rate me

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