我如何将信息传递给第二个表单对象

时间:2016-05-03 06:00:00

标签: vb.net

早上好。

我一直在努力。但我到了最后。我需要在周日的课程上提交这个。

我有一个按钮将我的数据发送到USB驱动器,我需要将它发送到第二个表单上的列表。我如何通过它。

这就是我所拥有的:

Private Sub btnTestResults_Click(sender As Object, e As EventArgs) Handles btnTestResults.Click

    '   Sends data to the frmresults form three, and creates the "consult.txt file on a
    '   USB drive for the Nurse can contact the patients.

    Dim objWriter As New IO.StreamWriter("e:\consult.txt")
    Dim frmThird As New frmElevatedResults
    Dim intHighCholesterol As Integer = 200I

    '   Write the file line by line until the file is completed.
    If IO.File.Exists("e:\consult.txt") Then
        If _intCholesterolLevel(intCount) < intHighCholesterol Then
            objWriter.WriteLine(_strNames(intCount))
            objWriter.WriteLine(_intCholesterolLevel(intCount))



        Else
            MsgBox("The file is not available. 
                    Please restart the program when the file is available", , "Error")
            objWriter.Close()
        End If

    End If


    Hide()
    frmThird.ShowDialog()
End Sub

非常感谢

1 个答案:

答案 0 :(得分:0)

一种选择是在frmElevatedResults上公开列表框:

  1. 通过工具箱将列表框控件添加到frmElevatedResults(如果尚未完成)。
  2. 在Project-Explorer中,点击Show all Files
  3. 打开frmElevatedResults.Designer.vb
  4. 找到列表框控件,例如listBox1 as ListBox
  5. 公开:public listBox1 as ListBox
  6. (我会包括屏幕,但我的VS不是英文)。

    在您的第一张表格上,您现在可以使用:

    Dim frmThird As New frmElevatedResults
    ...
    frmThird.listBox1.Items.Add(string.concat(_strNames(intCount), 
                                " - ", 
                                _intCholesterolLevel(intCount))
    ...
    Hide()
    frmThird.Show()
    

    或者你想放在那里的任何东西。