在VB.NET表单之间传递数据 [英] Passing Data between VB.NET forms

查看:153
本文介绍了在VB.NET表单之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单有一个按钮,点击它会弹出一个对话窗体。在此对话框内,用户需要选择一些数据,用户完成后,点击OK按钮。一旦他们单击确定按钮,它需要返回一个整数返回到上一个表单。



我创建了一个对话框,并尝试通过以下代码调用:

  Dim intResult as Integer = frmData.ShowDialog()

Debug.Writeline(intResult)

但是,似乎我只能返回DialogResults(中止,取消,忽略...)



我想知道如何无需创建一个公共变量并存储结果就可以尝试,

解决方案>

在对话框中创建一个返回值的属性。

 如果frmData.ShowDialog()不是DialogResult。取消
Dim值as integer = frmData.MyProperty
...
Endif


I have a form that has a button, when clicked it pops up a Dialog Form. Within this dialog form the user needs to select some data and when the user is finished they click the OK button. Once they click the OK button it needs to return an integer back to the previous form.

I created a Dialog Form and tried calling it via the code below:

Dim intResult as Integer = frmData.ShowDialog()

Debug.Writeline(intResult)

However, it seems I can only return DialogResults (Abort, Cancel, Ignore...)

I was wondering how I can try this without having to create a public variable and storing the result there.

解决方案

Create a property on the Dialog that will return the value.

If frmData.ShowDialog() Is Not DialogResult.Cancel
   Dim value as integer = frmData.MyProperty 
   ...
Endif

这篇关于在VB.NET表单之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆