将变量从 Windows 窗体传递到 Modal [英] Passing Variable from Windows form to Modal
问题描述
Windows 窗体、VB.我在网上搜索了正确的答案,没有骰子.要么他们错过了我想要完成的工作,要么在 CSHARP 中让我更难看到他们在做什么.我需要将主窗口窗体中的记录 Id 传递到模式对话框加载事件中.将整数 _CurrentProp 的值传递到对话框中.这是对话框构造函数和该对话框内的加载事件..
Windows Forms, VB. I have searched the web for the correct answer to this and no dice. Either they are missing on what I am trying to accomplish or are in CSHARP making it harder for me to see what they are doing. I have a need to pass a record Id from the main windows form into a modal Dialog Load Event.. I have tried throwing a with param in but then I have to change the Load event params and vb flags it.. I am trying to pass the value of _CurrentProp which is an integer into the dialog. This is the dialog constructor and the load event inside that dialog..
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 类中的一个全局变量,但我尝试的一切似乎都以一种或另一种方式失败......任何想法......
I am going to simply assign the value to a global variable inside the PropertySettings Class but everything I try seems to fail in one way or another... Any ideas...
推荐答案
添加一个公共属性 RecordID
到你的对话框窗口,然后像这样打开对话框
Add a public property RecordID
to your dialog window, then open the dialog like this
Dim _propertSettings As New PropertySettingsWindow()
_propertSettings.RecordID = 15
_propertSettings.ShowDialog()
在对话框表单中,您可以简单地使用
In the dialog form you can simply access the record id with
_properties = db.property_info_by_id(RecordID).ToList
<小时>
从 .NET Framework 4.0 开始,您可以使用自动实现的属性
Starting with .NET Framework 4.0, you can use auto-implemented properties
Public Property RecordID As Integer
使用以前的版本,您必须编写
With previous versions you would have to write
Private _recordID As Integer
Property RecordID As Integer
Get
Return _recordID
End Get
Set(ByVal value As Integer)
_recordID = value
End Set
End Property
这篇关于将变量从 Windows 窗体传递到 Modal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!