Public Class Form1 Private f2 As Form2 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If f2 Is Nothing Then f2 = New Form2 f2.Show() End If 'ある判定(=ここでは現在の秒が偶数であるかの確認)を行う。 Dim second As Integer = Now.Second If second Mod 2 = 0 Then f2.WriteMessage("現在の秒は偶数です。" & second, True) Else f2.WriteMessage("偶数じゃない!" & second, False) End If End Sub End Class
Public Class Form2 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim table As New DataTable table.Columns.Add("Message", GetType(String)) DataGridView1.DataSource = table End Sub Public Sub WriteMessage(ByVal message As String, ByVal isOK As Boolean) Dim table As DataTable = DataGridView1.DataSource table.Rows.Add(message) If Not isOK Then Dim gridRow As DataGridViewRow = DataGridView1.Rows(table.Rows.Count - 1) gridRow.Cells(0).Style.ForeColor = Color.Red End If End Sub End Class