stoow
July 8th, 2002, 09:46 AM
Hi i'm a java programmer trying to get to grips with VB.Net, i'm writing a program which has a Thread monitoring the clipboard for any changes, if a change has occurred I want a form to be notified of this change.
In Java its a case of using Observables, but i'm not entirely sure how to do this in VB. Can anyone help?
its really starting to get on my nerves, here is what i've done so far - its not getting anything off the clipboard at all
Sorry about the formatting/lack of it!
Imports System
Imports System.Threading
Imports System.Windows.Forms.Clipboard
Public Class ClipboardThread
'Dim localClip As Clipboard
Dim strClipboard As String
Dim strLastData As String
'Dim iData As IDataObject
'Dim textFormat As DataFormats.Format()
Sub MyThreadProc() '(ByRef localform As Form1)
While (True)
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData Is Nothing Then
'do nothing
Else
If iData.GetDataPresent(DataFormats.Text) Then
strClipboard = CType(iData.GetDataPresent(DataFormats.Text), String)
If strClipboard = strLastData Then
'do nothing
Else
'clipboard has changed
strLastData = strClipboard
'notify the form that it has changed
'localform.clipboard_Changed()
MsgBox("Clipboard changed!")
End If
End If
End If
End While
End Sub
'continually run
'get clipboard data
'check for change
'if changed notify in a messagebox
End Class
In Java its a case of using Observables, but i'm not entirely sure how to do this in VB. Can anyone help?
its really starting to get on my nerves, here is what i've done so far - its not getting anything off the clipboard at all
Sorry about the formatting/lack of it!
Imports System
Imports System.Threading
Imports System.Windows.Forms.Clipboard
Public Class ClipboardThread
'Dim localClip As Clipboard
Dim strClipboard As String
Dim strLastData As String
'Dim iData As IDataObject
'Dim textFormat As DataFormats.Format()
Sub MyThreadProc() '(ByRef localform As Form1)
While (True)
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData Is Nothing Then
'do nothing
Else
If iData.GetDataPresent(DataFormats.Text) Then
strClipboard = CType(iData.GetDataPresent(DataFormats.Text), String)
If strClipboard = strLastData Then
'do nothing
Else
'clipboard has changed
strLastData = strClipboard
'notify the form that it has changed
'localform.clipboard_Changed()
MsgBox("Clipboard changed!")
End If
End If
End If
End While
End Sub
'continually run
'get clipboard data
'check for change
'if changed notify in a messagebox
End Class