|
shu さん
Hongliang さん
畏れ入ります!
このようになっています。
ArryListに5個追加すると、5個め(arl(4))のみ画像の表示ができます。
Button3Clickの内容確認を実行しても
(0) System.Drawing.Imaging.Metafile
(1) System.Drawing.Imaging.Metafile
(2) System.Drawing.Imaging.Metafile
(3) System.Drawing.Imaging.Metafile
(4) System.Drawing.Imaging.Metafile
となりますので、ちゃんと入っていると思うのですが・・・
Dim arl As ArrayList = New ArrayList
'追加
Sub Button2Click(sender As Object, e As EventArgs)
Dim data As IDataObject = Clipboard.GetDataObject()
'クリップボードにデータがあるか調べる
If data IsNot Nothing Then
'MetaFilePict形式でデータをMemoryStreamとして取得する
Dim ms As System.IO.MemoryStream = _
DirectCast(data.GetData("MetaFilePict"), System.IO.MemoryStream)
If Not ms Is Nothing Then
'Imageオブジェクトに変換する
Debug.Print("get image!")
arl.Add(GetEnhMetafileOnClipboard(Me.Handle))
Else
Debug.Print("not image.")
End If
End If
End Sub
Function GetEnhMetafileOnClipboard( _
ByVal hWnd As IntPtr) As System.Drawing.Imaging.Metafile
Dim meta As System.Drawing.Imaging.Metafile = Nothing
If OpenClipboard(hWnd) Then
Try
If IsClipboardFormatAvailable(CF_ENHMETAFILE) <> 0 Then
Dim hmeta As IntPtr = GetClipboardData(CF_ENHMETAFILE)
meta = New System.Drawing.Imaging.Metafile(hmeta, True)
End If
Catch ex as Exception
Debug.Print(ex.Message)
Finally
CloseClipboard()
End Try
End If
Return meta
End Function
'内容確認
Sub Button3Click(sender As Object, e As EventArgs)
For i As Integer = 0 To arl.Count -1
Debug.Print( "(" & i & ") " & arl(i).GetType.tostring )
Next
End Sub
'表示
Sub Button4Click(sender As Object, e As EventArgs)
pictureBox1.Image = arl(numericUpDown1.Value)
End Sub
|