In your GIF, this app uses a custom Clipboard format (PXCEditCbData), so it cannot be generic
With this test, I get the size of the Rectangle from PXCEditCbData (nValues array), but it will be different for any other application :
Public Class Form1
Private Const WM_CLIPBOARDUPDATE As Integer = &H31D
<DllImport("User32.dll", SetLastError:=True)>
Private Shared Function AddClipboardFormatListener(hwnd As IntPtr) As Boolean
End Function
<DllImport("User32.dll", SetLastError:=True)>
Private Shared Function RemoveClipboardFormatListener(hwnd As IntPtr) As Boolean
End Function
Protected Overrides Sub OnHandleCreated(e As EventArgs)
MyBase.OnHandleCreated(e)
AddClipboardFormatListener(Me.Handle)
End Sub
Protected Overrides Sub OnHandleDestroyed(e As EventArgs)
MyBase.OnHandleDestroyed(e)
RemoveClipboardFormatListener(Me.Handle)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
If m.Msg = WM_CLIPBOARDUPDATE Then
GetClipboardContent()
End If
End Sub
Private Sub GetClipboardContent()
If Clipboard.ContainsImage() Then
Dim clipboardImage As Image = Clipboard.GetImage()
Dim nImageSize As Size = clipboardImage.Size
ElseIf Clipboard.ContainsData("PXCEditCbData") Then
Dim dataObject As Object = Clipboard.GetData("PXCEditCbData")
If TypeOf dataObject Is MemoryStream Then
Dim stream As MemoryStream = DirectCast(dataObject, MemoryStream)
' BBox [0 0 6.237762 148.957275]
Dim sResult As String = SearchForBBoxString(stream)
Dim sValues As String = sResult.Substring(6, sResult.Length - 7)
Dim sStringValues() As String = sValues.Split(" "c)
Dim nValues(3) As Single
For i As Integer = 0 To 3
nValues(i) = Single.Parse(sStringValues(i), CultureInfo.InvariantCulture)
Next
End If
End If
End Sub
Private Function SearchForBBoxString(stream As MemoryStream) As String
stream.Position = 0
Dim reader As New StreamReader(stream, Encoding.ASCII)
Dim sContent As String = reader.ReadToEnd()
Dim nStartIndex As Integer = sContent.IndexOf("BBox [")
If nStartIndex >= 0 Then
Dim nEndIndex As Integer = sContent.IndexOf("]", nStartIndex)
If nEndIndex > nStartIndex Then
Dim sString As String = sContent.Substring(nStartIndex, nEndIndex - nStartIndex + 1)
Return sString
End If
End If
Return Nothing
End Function
End Class