473,661 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EditCop y()
'I then declare an IDataObject
Dim data As IData = Clipboard.GetDa taObject()

'I THen check to see whether emf data is present
If (data.GetDataPr esent(DataForma ts.EnhancedMeta file)) 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(d ata.GetData(Dat aFormats.Enhanc edMetafile))
'Img = CType(data.GetD ata(DataFormats .EnhancedMetafi le)),
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.Ima ge= 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 2148
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 "GetWindowD C" _

(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 GetWindowPictur e(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(h Wnd, r)

w = r.Right - r.Left

h = r.Bottom - r.Top

bm = New Bitmap(w, h)

g = g.FromImage(bm)

hdcSrc = GetWindowDC(hWn d)

hdcDest = g.GetHdc

BitBlt( _

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

g.ReleaseHdc(hd cDest)

ReleaseDC(hWnd, hdcSrc)

Return bm

End Function

Ken

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

"andrew" <an*******@disc ussions.microso ft.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.EditCop y()
'I then declare an IDataObject
Dim data As IData = Clipboard.GetDa taObject()

'I THen check to see whether emf data is present
If (data.GetDataPr esent(DataForma ts.EnhancedMeta file)) 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(d ata.GetData(Dat aFormats.Enhanc edMetafile))
'Img = CType(data.GetD ata(DataFormats .EnhancedMetafi le)),
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.Ima ge= 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
43356
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 ActiveForm.ActiveControl.SelText, vbCFText
2
3257
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 DataObject() data.SetData(DataFormats.UnicodeText, True, value) Clipboard.SetDataObject(data,True) End Sub When I test it, I get an exception:
5
21016
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 windows explorer: when you do a right-click on a file and choose Copy, and than paste it somewhere in my application and vice versa.
2
2677
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 seems to work for me. A few people refer to txt.copy() txt.paste(), etc. I'm not sure if those are old functions, but they do not work for me. I've tried textbox1.selectall() - that works in selecting
7
11613
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 is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
1
4901
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 Globals.Profiles.Range("ProfileChart").CopyPicture(Excel.XlPictureAppearance.xlScreen, Excel.XlCopyPictureFormat.xlPicture) to paste the chart into a picturebox I first tried Me.PictureBox1.Image = Clipboard.GetImage
8
2604
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 clipboard : ====> Private Sub CopyToClipboard(ByVal Obj As PluginApp.PlugInReport) ' Creates a new data format.
9
4813
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
5103
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 about 20 textboxes on the form). Also to ensure that the button can't get used if the cursor isn't in a textbox field. And to ensure the contents of the clipboard are "text" contents that have been cut/copied from one of the textboxes on the form. ...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8754
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.