Copying the form on to Clipboard

I have a form in Visual basic that draws a chart on the form itself for the values in the database. I want to provide a button on the form, so that when user clicks the button, I want to copy the form on to the clipboard, so that user can paste the form on to Power point for presentation purposes. Can you suggest me any ideas or example codes?
ravinkAsked:
Who is Participating?
 
Erick37Connect With a Mentor Commented:
Previous code as answer... Thanks!

Regarding Access forms, I must admit that I do not have Access installed an cannot answer that question.  This ticle may, however, get you started:

"ACC: How to Capture Screens of Your Forms (95/97)"

"The following sample Visual Basic for Applications code captures an object on the screen in the Clipboard. Note that you can change the handle AccessHwnd in the sample code below to create screen shots of other applications, including specific objects within Microsoft Access."

http://support.microsoft.com/support/kb/articles/Q148/3/92.asp
0
 
mcriderCommented:
You can put a form on the clipboard this way:

Clipboard.Clear
Form1.Picture = Form1.Image
Clipboard.SetData Form1.Picture, vbCFBitmap




Cheers!®©
0
 
Erick37Commented:
"HOWTO: Copy the Screen or Active Window to the Clipboard from Visual Basic"

http://support.microsoft.com/support/kb/articles/Q240/6/53.ASP
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Erick37Commented:
Condensed version:

Option Explicit

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
   bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12

Private Sub Command1_Click()
   keybd_event VK_MENU, 0, 0, 0
   keybd_event VK_SNAPSHOT, 0, 0, 0
   keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
   keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
End Sub

Private Sub Form_Load()
   Command1.Caption = "Copy Me to ClipBoard"
End Sub
0
 
ravinkAuthor Commented:
mcrider,
Sorry, It is my mistake I mentioned it as form, but it is not a form. It is a UserControl. I created this user control and drawing lines on the control. I can place a button on this control, if we can implement copying mechanism of copying the control on to clipboard in this button. or I can place a button on the form along with this usercontrol, so as to implement the copying mechanism in the button.
0
 
ravinkAuthor Commented:
Erick37
  Your idea did work, but it is copying the other main forms along with this active form on to the clipboard. (The main form is bigger than the active form.)Is there any idea that I can just copy the active form or Just one OCX control on this form onto clipboard.
0
 
Erick37Commented:
Is this an MDI application?
0
 
ravinkAuthor Commented:
Yes, Is it possible to copy just the control on this form to the clipboard.
0
 
mcriderCommented:
Take a look at this Microsoft KB article:

HOWTO: Capture and Print the Screen, a Form, or any Window
http://support.microsoft.com/support/kb/articles/Q161/2/99.ASP?LNG=ENG&SA=MSDN&FR=0 

You can capture the control and put it into a picture, then put the picture on the clipboard using:

Clipboard.SetData Picture1.Picture, vbCFBitmap



Cheers!®©
0
 
Erick37Commented:
Ok, this code will copy the image of a control located on the form.
Put a picturebox on the form.
In this example, a FileListBox is captured and copied to clipboard:

Option Explicit
Private Declare Function BitBlt Lib "gdi32" _
    (ByVal hDestDC As Long, ByVal x As Long, _
    ByVal y As Long, ByVal nWidth As Long, _
    ByVal nHeight As Long, ByVal hSrcDC As Long, _
    ByVal xSrc As Long, ByVal ySrc As Long, _
    ByVal dwRop As Long) As Long

Private Sub Command1_Click()
    Dim PrevScaleMode As Long
    PrevScaleMode = Me.ScaleMode
    Me.ScaleMode = 3 'pixel
    With File1 'choose the control you wish to copy
    Picture1.Width = .Width
    Picture1.Height = .Height
    Call BitBlt(Picture1.hDC, 0, 0, .Width, .Height, Me.hDC, .Left, .Top, vbSrcCopy)
    Picture1.Refresh
    Picture1.Picture = Picture1.Image
    Clipboard.SetData Picture1.Picture
    Picture1.Picture = LoadPicture("")
    End With
    Me.ScaleMode = PrevScaleMode
End Sub

Private Sub Form_Load()
    Picture1.BorderStyle = 0 'none
    Picture1.AutoRedraw = True
    Picture1.Visible = False
    Picture1.ScaleMode = 3 'pixel
End Sub
0
 
Erick37Commented:
Slight modification:

'...
Clipboard.Clear
Clipboard.SetData Picture1.Picture, vbCFBitmap
'...
0
 
ravinkAuthor Commented:
Erick37
 I tried your code, but it is copying the whole screen with all background onto the clipboard. I tried with Frame control, List view control. Let me know if there is any fix that captures only the control.
Mcrider
  I will try the example you suggested.
Thanks Guys
0
 
Erick37Commented:
Make sure that the properties like .Width refer to the control named in the With statement.  Try to implicitly name them as in the following code.  I retried the code and it copied only the image of the FileListBox to the ClipBoard.  I used an MDI child form loaded by calling Form1.Show from the MDIMain_Load sub.

Child form code:

Option Explicit
Private Declare Function BitBlt Lib "gdi32" _
    (ByVal hDestDC As Long, ByVal x As Long, _
    ByVal y As Long, ByVal nWidth As Long, _
    ByVal nHeight As Long, ByVal hSrcDC As Long, _
    ByVal xSrc As Long, ByVal ySrc As Long, _
    ByVal dwRop As Long) As Long

Private Sub Command1_Click()
    Dim PrevScaleMode As ScaleModeConstants
    PrevScaleMode = Me.ScaleMode
    Me.ScaleMode = 3 'pixel

    Picture1.Width = File1.Width
    Picture1.Height = File1.Height
    Picture1.AutoRedraw = True
    Call BitBlt(Picture1.hDC, 0, 0, File1.Width, File1.Height, Me.hDC, File1.Left, File1.Top, vbSrcCopy)
    Picture1.Refresh
    Picture1.Picture = Picture1.Image
    Clipboard.Clear
    Clipboard.SetData Picture1.Picture, vbCFBitmap
    Picture1.Picture = LoadPicture("")
    Picture1.AutoRedraw = False

    Me.ScaleMode = PrevScaleMode
End Sub

Private Sub Form_Load()
    Picture1.BorderStyle = 0 'none
    Picture1.AutoRedraw = False
    Picture1.Visible = False
    Picture1.ScaleMode = 3 'pixel
End Sub

0
 
ravinkAuthor Commented:
Erick37
 It worked. Earlier my controls were in the splitter control, that is the reason it didn't work. But I moved them out of the spilitter and it worked. Please propose this answer, I will accept. And also, What do we need to do to implement this same thing in Microsoft Access forms?? Treat this as a new question if you want to..
Thanks.
Mcrider, Thanks to you too, for the suggestion of good example.
0
 
ravinkAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.