复制图片和文字到剪贴板在一起 [英] Copy image and text to clipboard together

查看:1700
本文介绍了复制图片和文字到剪贴板在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从一个图片框和文本从一个文本框复制图像到Windows剪贴板在一起,使他们可以粘贴到Word中。

I need to copy an image from a picture box and text from a textbox to the Windows clipboard together, so that they can be pasted into Word.

我用下面的code:

    Dim bmp As New Bitmap(pb1.Width, pb1.Height)
    pb1.DrawToBitmap(bmp, New Rectangle(0, 0, pb1.Width, pb1.Height))

    Dim dataobj As DataObject = New DataObject
    dataobj.SetText("This image is a graph")
    dataobj.SetImage(bmp)
    Clipboard.SetDataObject(dataobj, True)

    bmp.Dispose()

只有文字被复制,但注释掉的的setText 行导致的图像被复制。 任何帮助将是非常美联社preciated。

Only the text is copied, but commenting out the SetText line causes the image to be copied. Any help would be much appreciated.

推荐答案

中的数据格式检索根据即位图的情况下将粘贴到画图,文本将粘贴到记事本中。

The data formats are for retrieval depending on the context i.e. the bitmap will paste into Paint, and the text will paste into Notepad.

这code表明可以在.NET中获取它们。当您指定每种格式

This code demonstrates that you can retrieve them both in .NET. when you specify each format

Dim data As New DataObject()
data.SetData(DataFormats.Bitmap, True, Me.pb1.Image)
data.SetData(DataFormats.Text, True, "This image is a graph")
Clipboard.SetDataObject(data, True)
Dim bResult As Bitmap = Clipboard.GetData(DataFormats.Bitmap)
Dim tResult As String = Clipboard.GetData(DataFormats.Text)

作为另一项测试,把双方的图像和文字到Word,然后复制它们。然后检查什么的 tResult bResult (注释掉 SetDataObject 当然行)。你会发现, tResult 有你的字符串,但 bResult 为空。你也许可以解决这个问题,如果你能找出什么格式的位图时,它从Word复制,并使用该格式设定,当它在.NET。

As another test, put both the image and the text into Word, and copy them both. Then inspect what ends up in tResult and bResult (commenting out the SetDataObject line of course). You will notice that tResult has your string, but bResult is null. You might be able to solve it if you can figure out what format the bitmap is in when it's copied from Word, and use that format when setting it in .NET.

修改

复制只能从Word中的图像并把位图到 bResult ,但是当它与别的, Clipboard.GetData(DataFormats复制.Bitmap)为空。

Copying only the image from Word does put a bitmap into bResult, but when it is copied along with anything else, Clipboard.GetData(DataFormats.Bitmap) is null.

这篇关于复制图片和文字到剪贴板在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆