首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

form.show()可以用来传参到新窗体load事件中吗?该如何处理

2012-04-25 
form.show()可以用来传参到新窗体load事件中吗?form1:VB.NET codePrivate Sub testsub(ByVal s As String)

form.show()可以用来传参到新窗体load事件中吗?
form1:

VB.NET code
Private Sub testsub(ByVal s As String)        Form2.ShowDialog(ME, "test")    End Sub


form2:

如题, 比如在form1中form2.show(),show()默认可以接收一个form类型的值表示所有者,有没办法在form2中写点什么让它可以额外接收一个字符串类型的值,然后在form2_load中赋值给其他变量

不能用public传参进去,因为我会在form1中开多线程同时show出多个form2,用public的话无法区分是要传给哪个线程show出的form2

[解决办法]
1. 自己继承一个form,然后overload那个show()/showdialog()
2. 在form2里开个“中转”string的sub,比如:
VB.NET code
Public Class Form2    Dim theMsg As String    'Show的话    Sub GiveMeMsg(ByVal Msg As String)        theMsg = Msg        Me.Show()    End Sub    'ShowDialog的话    Sub GiveMeMsg(ByVal Msg As String, ByVal OwnerForm As Form)        theMsg = Msg        Me.ShowDialog(OwnerForm)    End SubEnd Class 

热点排行