Vb.net 将变量从Windows窗体传递到Modal

Vb.net 将变量从Windows窗体传递到Modal,vb.net,winforms,Vb.net,Winforms,Windows窗体,VB。我已经在网上搜索了这个问题的正确答案。要么他们错过了我正在努力实现的目标,要么他们在CSHARP中让我更难看到他们在做什么。我需要将记录Id从主windows窗体传递到模式对话框加载事件中。。我已经尝试抛出一个with param,但是我必须更改加载事件params并用vb标记它。。我试图将_CurrentProp的值传递到对话框中,它是一个整数。这是对话框构造函数和该对话框内的加载事件 Private Sub PropertySettingsMenuClick(ByV

Windows窗体,VB。我已经在网上搜索了这个问题的正确答案。要么他们错过了我正在努力实现的目标,要么他们在CSHARP中让我更难看到他们在做什么。我需要将记录Id从主windows窗体传递到模式对话框加载事件中。。我已经尝试抛出一个with param,但是我必须更改加载事件params并用vb标记它。。我试图将_CurrentProp的值传递到对话框中,它是一个整数。这是对话框构造函数和该对话框内的加载事件

Private Sub PropertySettingsMenuClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PropertyDetailsToolStripMenuItem.Click
Dim _propertSettings As New PropertySettingsWindow()
_propertSettings.ShowDialog()
End Sub


Private Sub PropertySettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim _properties As New List(Of property_info)
_properties = db.property_info.ToList
    For Each a In _properties
        If Not p_settingsCityList.Items.Contains(a.city) Then
            p_settingsCityList.Items.Add(a.city)
        End If
    Next

    For Each b In _properties
        If Not p_settingsPropertyList.Items.Contains(b.property_Name) Then
            p_settingsPropertyList.Items.Add(Convert.ToString(b.idProperties) + " -- " + b.property_Name)
        End If
    Next
    p_settingsZipCode.ReadOnly = True
    p_settings_Address.ReadOnly = True
    p_settings_PropertyName.ReadOnly = True

End Sub
我将简单地将值分配给PropertySettings类中的一个全局变量,但是我尝试的每件事似乎都以这样或那样的方式失败了。。。任何想法…

将公共属性RecordID添加到对话框窗口,然后像这样打开对话框

Dim _propertSettings As New PropertySettingsWindow()
_propertSettings.RecordID = 15
_propertSettings.ShowDialog()
在对话框窗体中,您只需使用

_properties = db.property_info_by_id(RecordID).ToList   
从.NET Framework 4.0开始,您可以使用自动实现的属性

Public Property RecordID As Integer
对于以前的版本,您必须编写

Private _recordID As Integer
Property RecordID As Integer
    Get
        Return _recordID
    End Get
    Set(ByVal value As Integer)
        _recordID = value
    End Set
End Property
将公共属性RecordID添加到对话框窗口,然后按如下方式打开对话框

Dim _propertSettings As New PropertySettingsWindow()
_propertSettings.RecordID = 15
_propertSettings.ShowDialog()
在对话框窗体中,您只需使用

_properties = db.property_info_by_id(RecordID).ToList   
从.NET Framework 4.0开始,您可以使用自动实现的属性

Public Property RecordID As Integer
对于以前的版本,您必须编写

Private _recordID As Integer
Property RecordID As Integer
    Get
        Return _recordID
    End Get
    Set(ByVal value As Integer)
        _recordID = value
    End Set
End Property

+1或使其成为窗体构造函数中的参数,以设置主属性-两者都同等有效。非常感谢我忘记了这样做,我在上一个vb.net mvc3项目中使用了大量的主属性..是的,表单只是一个类,你可以用它做任何你可以用类做的事情…+1,或者让它成为表单构造函数中的一个参数来设置一个主属性-两者都同样有效。非常感谢我忘记了这么做,我在上一个vb.net mvc3项目中使用了大量的参数。是的,表单只是一个类,你可以用它做任何你可以用类做的事情。。。