Pulling a bitmap off the clipboard.
Option Strict On
Option Explicit On
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Public Class WinApp
Inherits System.Windows.Forms.Form
Private m_PB As PictureBox
<STAThread()> _
Shared Sub Main()
Application.Run(New WinApp())
End Sub
Public Sub New()
Me.Text = "This is my form"
m_PB = New PictureBox()
m_PB.Location = New Point(0, 0)
m_PB.Size = Me.Size
m_PB.Image = GetImageFromClipboard()
If Not m_PB.Image Is Nothing Then
Me.ClientSize = New Size(m_PB.Image.Width, m_PB.Image.Height)
m_PB.Size = Me.ClientSize
End If
Me.Controls.Add(m_PB)
End Sub
Public Function GetImageFromClipboard() As Image
If Not Clipboard.GetDataObject() Is Nothing Then
Dim dobj As IDataObject = Clipboard.GetDataObject()
If dobj.GetDataPresent(DataFormats.Bitmap) Then
Dim img_obj As Object = dobj.GetData(DataFormats.Bitmap)
Return CType(img_obj, Bitmap)
End If
End If
End Function
End Class