[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
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?
Re: Screen capture of a MDI children
It is not copying the exact dimensions... it is copying abit of the MDI parent too...
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?
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
Re: Screen capture of a MDI children
That worked a treat! Thanks!