harzem 06-03-2005, 03:02 AM I have a picturebox called "Picture1" (an interesting name, isn't it?).
Now I want to copy it to clipboard.
I wrote:
Private Sub Command1_Click()
Clipboard.Clear
Clipboard.SetData Picture1.Picture
End Sub
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?
spikey_richie 06-03-2005, 05:01 AM Copied from MSDN
Syntax
object.SetData [data], [format]
The SetData method syntax has these parts:
Part Description
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.
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)
harzem 06-03-2005, 06:19 AM You mean?
blastoboy1000 06-03-2005, 06:37 AM You need to specify what type of data you're copying to the clipboard. Those are the constants for specifying the data.
spikey_richie 06-03-2005, 06:44 AM You need to use the OPTIONAL type - in your case VBCFBitmap
harzem 06-03-2005, 06:45 AM I know the constant, I've already tried
Clipboard.SetData Picture1.Picture, vbCFBitmap
'or
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.
spikey_richie 06-03-2005, 06:58 AM Okay, try setting the focus on the picture then
Clipboard.SetData Screen.ActiveControl.Picture
harzem 06-03-2005, 07:19 AM Still not working...
spikey_richie 06-03-2005, 07: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
clicked command1
ran mspaint
ctrl + v and there it is!
What image format are you using for the picture1.picture property? .GIF? .TIFF? .JPEG?
harzem 06-03-2005, 07: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)
next
So I don't have a jpg or Gif or anything.
spikey_richie 06-03-2005, 07:59 AM You're right, it doesn't work! Interesting... i'll get back to you on that one.
Diurnal 06-03-2005, 08: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:
Option Explicit
Private Sub Command1_Click()
'Clear the clipboard and copy the picture box image.
Clipboard.Clear
Clipboard.SetData Picture1.Image
End Sub
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)
Next
End Sub
harzem 06-03-2005, 08: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 !!!
|