Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
'This class is used to operating systems clipboard. Thread is most important thing.
Public Class ClipBoard
Dim str As String
Public Function GetText() As String
Dim t As New System.Threading.Thread(AddressOf GetTextThreaded)
t.SetApartmentState(Threading.ApartmentState.STA)
t.Start()
t.Join()
Return str
End Function
Public Sub SetText(ByVal s As String)
str = s
Dim t As New System.Threading.Thread(AddressOf SetTextThreaded)
t.SetApartmentState(Threading.ApartmentState.STA)
t.Start()
t.Join()
End Sub
Private Sub GetTextThreaded()
Dim o As System.Windows.Forms.IDataObject
o = System.Windows.Forms.Clipboard.GetDataObject()
If (o Is Nothing) Then
str = ""
Else
str = o.GetData(System.Windows.Forms.DataFormats.StringFormat)
End If
End Sub
Private Sub SetTextThreaded()
System.Windows.Forms.Clipboard.SetDataObject(str, True)
End Sub
End Class
Usage:
'Copy to clipboard
Dim cb As New ClipBoard()
cb.SetText("Whatever")