Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim f As New Form2() f.Text = "Form2 - " & Now.ToString() f.Show(Me) End Sub End Class
Public Class Form2 Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim human1 As New BarcodeReader(TextBox1.Text) human1.DataReceived() End Sub End Class Public Class BarcodeReader ''' <summary>受信データ</summary> Private Shared g_Data As String = "" Public Sub DataReceived() MsgBox(g_Data) End Sub Public Sub New() End Sub Public Sub New(s As String) g_Data = s End Sub End Class
Public Class Form2 Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim human1 As New BarcodeReader() human1.DataReceived(TextBox1.Text) End Sub End Class Public Class BarcodeReader ''' <summary>受信データ</summary> Private Shared g_Data As String = "" Public Sub DataReceived(s As String) g_Data = s MsgBox(g_Data) End Sub End Class
Public Class Form2 Private WithEvents human As New BarcodeReader() Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click human.DataReceived() End Sub Private Sub human_RequireData(sender As Object, e As BarcodeReader.RequireEventArgs) Handles human.RequireData e.Data = TextBox1.Text End Sub End Class Public Class BarcodeReader ''' <summary>受信データ</summary> Private Shared g_Data As String = "" ''' <summary>データ受信用イベント</summary> Public Event RequireData As EventHandler(Of RequireEventArgs) ''' <summary>イベントを通じてデータを受信する</summary> Private Sub ReceiveText() Dim e As New RequireEventArgs() RaiseEvent RequireData(Me, e) g_Data = e.Data End Sub Public Sub DataReceived() ReceiveText() MsgBox(g_Data) End Sub ''' <summary>データ受信イベント引数</summary> Public Class RequireEventArgs Inherits EventArgs Public Property Data As String End Class End Class