Microsoft KB Archive/193593

= PRB: Cannot Paste PrintScreen Result to OLE Control =

Article ID: 193593

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q193593



SYMPTOMS
Pressing the ALT+PRINTSCRN key combination turns the OLE control's PasteOK property to False, and the bitmap in the clipboard cannot be pasted to the OLE control.



CAUSE
There are two kinds of Clipboard formats; one is the traditional format and the other is the OLE format. Microsoft's Visual Basic OLE control is designed to hold the objects that can either be linked or embedded in the control. It requires the clipboard to contain the OLE information to be pasted into it. However, after pressing the ALT+PRINTSCRN key combination, the clipboard format is in the traditional format. For the same reason, simple metafiles in the clipboard cannot be pasted into the OLE control either.



RESOLUTION
To workaround this problem, the clipboard format needs to be transformed from traditional format to OLE format.



STATUS
This behavior is by design.



Steps to Reproduce and Work Around Behavior
The following is an example of using a Rich Textbox to transform the clipboard format from traditional format to OLE format and make the paste possible. The basic idea is to paste the bitmap from the clipboard to a Rich Textbox and then copy it back from the Rich Textbox to the clipboard. In the example, the SendKeys function is used to paste to and copy from the clipboard.

 Create a Standard EXE project in Visual Basic. Form1 is created by default. Put an OLE control on Form1 and keep the default name, OLE1. Click Cancel when the "Insert Object" dialog box comes up. Put a CommandButton on Form1 and keep the default name, Command1.  Add the following code to the code window of Form1: Private Sub Command1_Click if OLE1.PasteOk = True then OLE1.Paste else msgbox "Can not paste!" End if     End Sub  Run the application. Pressing the ALT+PRINTSCRN key combination and then click the CommandButton. The message box "Can not paste!" is displayed, demonstrating the problem.</li> Stop the application.</li> Select Components from the Project menu and check "Microsoft Rich Textbox Control X.0."</li> Add a Rich Textbox to Form1 and keep the default name, RichTextBox1. Make sure its Visible property is set to True and its TabStop property is set to False. Make the Rich Textbox as small as possible and hide it under the CommandButton (because you don't want it to show on the screen). If necessary, right-click on the Rich Textbox and click "Send to Back."</li>  Change the Command1_Click event handler to be: Private Sub Command1_Click ' use RichTextBox to transform the clipboard info RichTextBox1.TextRTF = "" RichTextBox1.SetFocus SendKeys "^v", True SendKeys "^+{HOME}", True SendKeys "^c", True RichTextBox1.TextRTF = ""

if OLE1.PasteOk = True then OLE1.Paste else msgbox "Can not paste!" End if     End Sub </li> Run the application again. Press the ALT+PRINTSCRN key combination and then click on Command1. This time the screen capture is pasted to the OLE control.</li></ol>

Additional query words: kbDSupport kbDSD kbVBp kbVBp500 kbVBp600 kbOLE kbClipboard

Keywords: kbprb KB193593

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.