'FormUARTから呼ばれる
Public Sub AddText(ByVal strGetText As String)
TextBox1.Text = TextBox1.Text + strGetText
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
UART1 = New FormUART()
UART1.Visible = True
UART1.SetForm(Me) 'Form1のインスタンスを渡す
End Sub
End Class
Public Class FormUART
Dim F1 As Form1
Delegate Sub dlgAddText(ByVal GetText As String)
Public Sub AddText(ByVal strText As String)
F1.AddText(strText)
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim inStr As String = SerialPort1.ReadChar()
Me.Invoke(New dlgAddText(AddressOf Me.AddText), _
New Object() {inStr})
End Sub
Public Sub SetForm(ByVal f As Form1)
F1 = f
End Sub
Private Sub FormUART_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.Open()
End Sub
End Class