PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
The object is currently in use elswehere
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
The object is currently in use elswehere
![]() |
The object is currently in use elswehere |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Below is a snippit of code that is supposed to capture the image of a
visible window, and copy it to a picturebox control on my form. My picturebox control is on a tab in a page control. Everything seems to work fine except when I select the page that the picturebox is on to make it visible, I get a System.InvalidOperationException in system.drawing.dll 'The object is currently in use elsewhere'. Any ideas? this.PictureBox1.Image = CaptureWindow(hwndWindowToCapture) public static System.Drawing.Bitmap CaptureWindow(IntPtr hWndWindowToCapture) { RECT pRect; pRect.iLeft = 0; pRect.iRight = 0; pRect.iBottom = 0; pRect.iTop = 0; int iRetVal = User32.GetWindowRect(hWndWindowToCapture, ref pRect); int iWidth = pRect.iRight - pRect.iLeft; int iHeight = pRect.iBottom - pRect.iTop; POINTAPI pPoint; pPoint.iY = pRect.iTop; pPoint.iX = pRect.iLeft; iRetVal = User32.ScreenToClient(hWndWindowToCapture, ref pPoint); pRect.iLeft = pPoint.iX; pRect.iTop = pPoint.iY; System.Drawing.Bitmap pBitmap = new System.Drawing.Bitmap(iWidth, iHeight); System.Drawing.Graphics pGraphics = System.Drawing.Graphics.FromImage(pBitmap); IntPtr iHDCWindow = User32.GetDC(hWndWindowToCapture); try { IntPtr iHDCGraphic = pGraphics.GetHdc(); //System.Drawing.Graphics tg = System.Drawing.Graphics.FromHdc( hDc ); iRetVal = StretchBlt( iHDCGraphic, 0, 0, iWidth, iHeight, (int)iHDCWindow, pRect.iLeft, pRect.iTop, iWidth, iHeight, SRCCOPY | CAPTUREBLT); } finally { User32.ReleaseDC(hWndWindowToCapture,iHDCWindow); } return pBitmap; } |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

