选择ComboBox值时,输出特定文本(Visual Basic)

时间:2015-12-27 20:05:55

标签: vb.net combobox textbox

我正在为临床支持创建一个决策界面,其中包含大量具有布尔值“是|否”的组合框。但我想要如此,如果用户选择是或否,则可以在底部单击按钮然后出现另一个窗体,说明他们是否患有癌症。

例如,如果用户在comboBox中单击“是”,然后单击“提交”按钮,则会出现另一个表单,文本框将显示他们是否患有癌症。有人能够提供一个如何工作的例子吗?我有组合框的表单,链接到另一个表单的按钮,以及第二个表单内的文本框....但我无法获取两个表单之间的信息。

我目前的代码是

Private Sub submit_Click(sender As Object, e As EventArgs) Handles submit.Click 
    If (RectalBleeding.SelectedItem = "Yes") Then Outcome.OutcomeBox.Text = "you have cancer" End If Outcome.Show()
End Sub

尝试链接的特定组合框称为“RectalBleeding”。决策界面表单上的按钮称为“提交”,第二种形式称为“结果”。结果中的框被称为'outcomeBox'我想要它,以便如果在comboBox中选择'是',则用户点击'提交'第二个表单出现,并在文本框中显示“你有癌症”

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用公共属性和构造函数在两个表单之间传递值。以下是一些使用这些工具的代码。

以下是主要表单的代码:

Public Class Form1
    Private frm As Outcome
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        AddDecision()
    End Sub
    Private Sub AddDecision()
        RectalBleeding.Items.Add("Yes")
        RectalBleeding.Items.Add("No")
    End Sub

    Private Sub Submit_Click(sender As Object, e As EventArgs) Handles Submit.Click
        If RectalBleeding.Text = "Yes" Then
            frm = New Outcome("You have cancer")
        Else
            frm = New Outcome("You don't have cancer")
        End If
        frm.Show()
    End Sub
End Class

以及结果表格

Public Class Outcome
    Private _Decision As String
    Public Property Decision() As String
        Get
            Return _Decision
        End Get
        Set(ByVal value As String)
            _Decision = value
        End Set
    End Property
    Private Sub Outcome_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        FillTextBox()
    End Sub

    Public Sub New(ByVal results As String)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.Decision = results
    End Sub
    Private Sub FillTextBox()
        outcomeBox.Text = Me.Decision
    End Sub
End Class