Help on Copying a picture box's contents (controls and all) to the clipboard. 
Author Message
 Help on Copying a picture box's contents (controls and all) to the clipboard.

Hi,

I need to find a way to copy the entire contents of a form or picturebox to
the clipboard as an image that I can then paste back into Microsoft Word.

I can copy just the picture to the picturebox but cannot seem to be able to
copy the controls as well.  The problem is that I had to create a custom
graph engine to display a special type of graph and now they want it pasted
into a word document that I am generating.

Everything is being generated as lines, shapes and captions in one picture
box.

Hope that is enough information!  I really need to get this working.

Thanks in advance,
Raffi Oshagan
Darwin Consulting.



Sun, 22 Oct 2000 03:00:00 GMT  
 Help on Copying a picture box's contents (controls and all) to the clipboard.

The only way to get a picture of controls within a picturebox is to take a
screen shot:

Get the API declares out of the API viewer.

Sub CopyScreen(canvas As Object)
Dim screendc&
    canvas.AutoRedraw = True
    screendc = CreateDC("DISPLAY", "", "", 0&)
    tempLong = StretchBlt(canvas.hDC, 0, 0, canvas.Width, canvas.Height,
screendc, 0, 0, Screen.Width, Screen.Height, SRCCOPY)
    tempLong = DeleteDC(screendc)
    canvas.AutoRedraw = False

End Sub

The above takes a shot of the whole screen and resizes it to the
destination, but you can easily see how to modify it to capture a portion
of the screen.  It will, of course, only work if the source is fully
visible!

Jim Deutch
MS Dev MVP



Quote:
> Hi,

> I need to find a way to copy the entire contents of a form or picturebox
to
> the clipboard as an image that I can then paste back into Microsoft Word.

> I can copy just the picture to the picturebox but cannot seem to be able
to
> copy the controls as well.  The problem is that I had to create a custom
> graph engine to display a special type of graph and now they want it
pasted
> into a word document that I am generating.

> Everything is being generated as lines, shapes and captions in one
picture
> box.

> Hope that is enough information!  I really need to get this working.

> Thanks in advance,
> Raffi Oshagan
> Darwin Consulting.



Sun, 22 Oct 2000 03:00:00 GMT  
 Help on Copying a picture box's contents (controls and all) to the clipboard.

Hi Raffi,

|Hi,
|
|I need to find a way to copy the entire contents of a form or picturebox to
|the clipboard as an image that I can then paste back into Microsoft Word.
|
|I can copy just the picture to the picturebox but cannot seem to be able to
|copy the controls as well.  The problem is that I had to create a custom
|graph engine to display a special type of graph and now they want it pasted
|into a word document that I am generating.
|
|Everything is being generated as lines, shapes and captions in one picture
|box.
|
|Hope that is enough information!  I really need to get this working.
|
|Thanks in advance,
|Raffi Oshagan
|Darwin Consulting.

Maybe this can work for you, it will copy a control to a picturebox using the WM_PAINT message.

Use it like this:

For Each Control In SourceContainer.Controls
   PaintControl Control, DestPictureBox
Next Control
ClipBoard.SetData DestPictureBox.Picture, vbCFBitmap

Sub PaintControl(Control As Object, PictureBox As PictureBox)

  Dim rcClient As RECT
  Dim rcWindow As RECT
  Dim rcParent As RECT
  Dim ctrlhWnd As Long

  On Error Resume Next
  ctrlhWnd = Control.hWnd

  If Not Err Then
    PictureBox.AutoRedraw = True
    Call GetClientRect(ctrlhWnd, rcClient)
    Call GetWindowRect(ctrlhWnd, rcWindow)
    Call GetWindowRect(GetParent(ctrlhWnd), rcParent)
    Call OffsetRect(rcWindow, -rcParent.Left, -rcParent.Top)
    tmpDC = CreateCompatibleDC(PictureBox.hdc)
    tmpBM = CreateCompatibleBitmap(PictureBox.hdc, rcClient.Right, rcClient.Bottom)
    oldBM = SelectObject(tmpDC, tmpBM)
    Call SendMessage(ctrlhWnd, WM_PAINT, tmpDC, 0)
    Call BitBlt(PictureBox.hdc, rcWindow.Left, rcWindow.Top, rcClient.Right, rcClient.Bottom, tmpDC, 0, 0, vbSrcCopy)
    Call SelectObject(tmpDC, oldBM)
    Call DeleteObject(tmpBM)
    Call DeleteDC(tmpDC)
    PictureBox.AutoRedraw = False
    PictureBox.Refresh
  End If

End Sub

Hope this helps..

-John



Sun, 22 Oct 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help on Copying a picture box's contents (controls and all) to the clipboard.

2. Help on Copying a picture box's contents (controls and all) to the clipboard.

3. Copying the contents of a picture box to clipboard

4. Copying DBGrid contents to clipboard (Or copying a table from a Data component to clipboard)

5. How to copy contents of control to clipboard?

6. Copy contents of a control to the clipboard

7. copying contents of one picture box to another

8. Copy picture: Clipboard -> Picture object

9. Copy Picture Control Contents to Memory

10. RichText box control and Clipboard, cut, copy and paste

11. Copying form field contents & formatting to clipboard

12. Copy textbox-content to clipboard

 

 
Powered by phpBB® Forum Software