06-03-2005, 04:02 AM
I have a picturebox called "Picture1" (an interesting name, isn't it?).
Now I want to copy it to clipboard.
Private Sub Command1_Click()
But it doesn't work. It clears the board, and copies nothing into it.
I guess the problem is the types. Clipboard.SetData gets an IPictureDisp but Picture1.Picture is a StdPicture.
Any ideas to solve this problem?
06-03-2005, 06:01 AM
Copied from MSDN
object.SetData [data], [format]
The SetData method syntax has these parts:
object Required. Anobject expression that evaluates to an object in the Applies To list.
data Optional A variant containing the data to be passed to the DataObject object.
format Optional. A constant or value that specifies the format of the data being passed, as described in Settings.
The settings for format are:
Constant Value Description
vbCFText 1 Text (.txt files)
vbCFBitmap 2 Bitmap (.bmp files)
vbCFMetafile 3 Metafile (.wmf files)
vbCFEMetafile 14 Enhanced metafile (.emf files)
vbCFDIB 8 Device-independent bitmap (DIB)
vbCFPalette 9 Color palette
vbCFFiles 15 List of files
vbCFRTF -16639 Rich text format (.rtf files)
06-03-2005, 07:19 AM
06-03-2005, 07:37 AM
You need to specify what type of data you're copying to the clipboard. Those are the constants for specifying the data.
06-03-2005, 07:44 AM
You need to use the OPTIONAL type - in your case VBCFBitmap
06-03-2005, 07:45 AM
I know the constant, I've already tried
Clipboard.SetData Picture1.Picture, vbCFBitmap
Clipboard.SetData Picture1.Picture, vbCFDIB
but seems not to work.
I would send you my code, but it is so short, all is I posted above. I draw into Picture1 by Picture.Line (blabla)
Drawing is fine, but copying is not. Doesn't copy anything.
06-03-2005, 07:58 AM
Okay, try setting the focus on the picture then
06-03-2005, 08:19 AM
Still not working...
06-03-2005, 08:38 AM
I've just tried it and it works!
created a new project
Added a picture box and a command button
pasted in your code (with NO other code)
Chose a .JPG image for the picture box
ran the project
ctrl + v and there it is!
What image format are you using for the picture1.picture property? .GIF? .TIFF? .JPEG?
06-03-2005, 08:54 AM
I draw picture1 myself. It is a color-gradient generator, and draws a gradient into a picturebox. First I was drawing directly onto the form. Later, in another thread, I was told to draw into a picturebox so that I can copy into clipboard.
So its property is nothing.
My code that draw into it is (only an example, not a gradient now) is
dim i as integer
for i=0 to Picture1.Width
Picture1.Line ( i , 0 ) - ( i , Picture1.Height ) , RGB(rnd*256,256,256)
So I don't have a jpg or Gif or anything.
06-03-2005, 08:59 AM
You're right, it doesn't work! Interesting... i'll get back to you on that one.
06-03-2005, 09:08 AM
I'm assuming you are using persistent graphics to draw your image. If you draw your image, there isn't a picture loaded. Use the image property of the picturebox to set your graphic data:
Private Sub Command1_Click()
'Clear the clipboard and copy the picture box image.
Private Sub Form_Load()
'Set picture box persistant graphics.
Me.Picture1.AutoRedraw = True
'Create an image in the picturebox.
Dim i As Integer
For i = 0 To Picture1.Width
Picture1.Line (i, 0)-(i, Picture1.Height), RGB(Rnd * 256, 256, 256)
06-03-2005, 09:13 AM
I can't believe myself that I have forgotten to turn on Autoredraw!!!
Thank a lot both diurnal and spikey, the problem is over :D !!!