473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Unable to copy from clipboard

I have a MSchart object (COM Component) which I wish to
insert as an image into a picture box so that I can print
it out.

'I call the chart controls's EditCopy to pass data to the
clipboard.

Dim Img As Image
MyChart.EditCopy()
'I then declare an IDataObject
Dim data As IData = Clipboard.GetDataObject()

'I THen check to see whether emf data is present
If (data.GetDataPresent(DataFormats.EnhancedMetafile) ) Then
'(Checking this statement in at debug evaluates to true)(I
also am satisfied that the data is on the clipboard
because I am able to Paste Special it into EXCEL)
'I then try and recreate the emf as an image and have
tried the following combinations
'Img.FromFile(data.GetData(DataFormats.EnhancedMet afile))
'Img = CType(data.GetData(DataFormats.EnhancedMetafile)),
Image)
UNFORTUNATELY THE ABOVE CODE SEEMS TO RETURN NOTHING FOR
THE Img VARIABLE, AND INDICATES TO ME THAT I HAVE TO
SOMEHOW INSTATIATE AND CONSTRUCT THE Img FROM THE METAFILE
DATA, HOWEVER I HAVE NO IDEA HOW TO DO THIS.
'I then hope to assign my Image to the PictureBox Control
PictureBox1.Image= Img
End If

I PRESUME IT IS POSSIBLE TO COPY IMAGES OF COM OBJECTS TO
WIN FORM PICTURE BOXES (WITHOUT RESORTING TO PHOTOCOPYING
AND SCANNING!), CAN ANYONE GIVE ME SOME POINTERS PLEASE.

THANKS IN ADVANCE

ANDREW
Nov 20 '05 #1
1 2118
Hi,

This procedure will create a bitmap from a form or control given its hwnd.
You can print the bitmap.

Private Structure RECT

Public Left As Integer

Public Top As Integer

Public Right As Integer

Public Bottom As Integer

End Structure

Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Integer,
_

ByRef lpRect As RECT) As Integer

Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" _

(ByVal hDestDC As Integer, ByVal x As Integer, _

ByVal y As Integer, ByVal nWidth As Integer, _

ByVal nHeight As Integer, ByVal hSrcDC As Integer, _

ByVal xSrc As Integer, ByVal ySrc As Integer, _

ByVal dwRop As Integer) As Integer

Public Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" _

(ByVal hwnd As Integer) As Integer

Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Integer, _

ByVal hObject As Integer) As Integer

Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Integer, _

ByVal hdc As Integer) As Integer

Public Const SRCCOPY As Integer = &HCC0020

Public Const SRCINVERT As Integer = &H660046

Public Const MERGECOPY As Integer = &HC000CA

Public Const MERGEPAINT As Integer = &HBB0226

Private Function GetWindowPicture(ByVal hWnd As Integer) As Bitmap

Dim g As Graphics

Dim hdcDest As IntPtr

Dim hdcSrc As Integer

Dim bm As Bitmap

Dim r As New RECT()

Dim w, h As Integer

GetWindowRect(hWnd, r)

w = r.Right - r.Left

h = r.Bottom - r.Top

bm = New Bitmap(w, h)

g = g.FromImage(bm)

hdcSrc = GetWindowDC(hWnd)

hdcDest = g.GetHdc

BitBlt( _

hdcDest.ToInt32, 0, 0, w, h, hdcSrc, 0, 0, SRCCOPY)

g.ReleaseHdc(hdcDest)

ReleaseDC(hWnd, hdcSrc)

Return bm

End Function

Ken

----------------------------

"andrew" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
I have a MSchart object (COM Component) which I wish to
insert as an image into a picture box so that I can print
it out.

'I call the chart controls's EditCopy to pass data to the
clipboard.

Dim Img As Image
MyChart.EditCopy()
'I then declare an IDataObject
Dim data As IData = Clipboard.GetDataObject()

'I THen check to see whether emf data is present
If (data.GetDataPresent(DataFormats.EnhancedMetafile) ) Then
'(Checking this statement in at debug evaluates to true)(I
also am satisfied that the data is on the clipboard
because I am able to Paste Special it into EXCEL)
'I then try and recreate the emf as an image and have
tried the following combinations
'Img.FromFile(data.GetData(DataFormats.EnhancedMet afile))
'Img = CType(data.GetData(DataFormats.EnhancedMetafile)),
Image)
UNFORTUNATELY THE ABOVE CODE SEEMS TO RETURN NOTHING FOR
THE Img VARIABLE, AND INDICATES TO ME THAT I HAVE TO
SOMEHOW INSTATIATE AND CONSTRUCT THE Img FROM THE METAFILE
DATA, HOWEVER I HAVE NO IDEA HOW TO DO THIS.
'I then hope to assign my Image to the PictureBox Control
PictureBox1.Image= Img
End If

I PRESUME IT IS POSSIBLE TO COPY IMAGES OF COM OBJECTS TO
WIN FORM PICTURE BOXES (WITHOUT RESORTING TO PHOTOCOPYING
AND SCANNING!), CAN ANYONE GIVE ME SOME POINTERS PLEASE.

THANKS IN ADVANCE

ANDREW

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tor Inge Rislaa | last post by:
Copy, Cut and Paste How to code the Copy, Cut and Paste functionality in VB.NET. In VB 6.0 I used the following code: 'For Copy Clipboard.Clear Clipboard.SetText...
2
by: Shayne H | last post by:
I am trying to write a method to copy some text to the clipboard, and leave a copy of it there after the application has exited. Sub CopyToClipboard(ByVal value As Object) Dim data As New...
5
by: DraguVaso | last post by:
Hi, I'm looking for a way to Copy and Paste Files to the clipboard. I found a lot of articles to copy pieces of text and bitmaps etc, but nog whole files. Whay I need is like you have in...
2
by: Keith | last post by:
I'm trying to come up with a way to create a contextmenu that will do all the "standard" functions (cut, copy, paste, undo, etc). There seems to be a lot of information out there - but nothing...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
1
by: Sai | last post by:
I am trying to copy a range as a picture from excel and paste that into a picturebox on a form. The code I am using to copy is...
8
by: serge calderara | last post by:
Dear all, I have an treeview control with different node object, I would like to implement the Copy/Paste function of an object . For that I am using the folowing function to copy teh object to...
9
by: Alan T | last post by:
Any source code example I can use to save the clipboard content to an object, then I will do a copy and paste, finally put back the 'saved' clipboard content back to clipboard ?
17
by: Steve | last post by:
I'm trying to code cut, copy, and paste in vb 2005 so that when the user clicks on a toolbar button, the cut/copy/paste will work with whatever textbox the cursor is current located in (I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.