清除剪贴板不删除图像?

时间:2019-03-08 15:23:33

标签: vb.net winforms

我有一个Windows窗体,可将图像添加到剪贴板中以进行处理,然后当我尝试清除剪贴板时,如果我使用Excel,我仍然会在剪贴板中看到图像。为什么不清除?

Dim xlsApp1 As Object
Dim xlsWB As Object
Dim xlsSheet As Object
xlsApp1 = CreateObject("Excel.Application")
xlsWB = xlsApp1.Workbooks
xlsApp1.DisplayAlerts = False
xlsWB.Open("myexcel")
xlsSheet = xlsApp1.ActiveSheet

For Each xlsShape As Excel.Shape In xlsSheet.Shapes
    xlsShape.Copy()
    If xlsShape.Name = "Picture 1" Then
        'process the image
    End If
next

xlsWB.Close()
xlsApp1.Quit()

    Try
        Marshal.ReleaseComObject(xlsSheet)
        Marshal.ReleaseComObject(xlsWB)
        Marshal.ReleaseComObject(xlsApp1)
        xlsSheet = Nothing
        xlsWB = Nothing
        xlsApp1 = Nothing
    Catch ex As Exception
        xlsSheet = Nothing
        xlsWB = Nothing
        xlsApp1 = Nothing
    Finally
        GC.Collect()
        GC.WaitForPendingFinalizers()
        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Try

Clipboard.Clear()
Clipboard.SetDataObject(0)
'but still see it in the clipboard.

 'close excel ect.....

0 个答案:

没有答案