开发者

Way to pass data between forms (VB 2008)

开发者 https://www.devze.com 2023-04-10 14:08 出处:网络
Is this way a \"right\" way to pass data between two forms? \'Form1 code Public Class Form1 Public str As New String = \"This is the string\"

Is this way a "right" way to pass data between two forms?

'Form1 code

Public Class Form1

Public str As New String = "This is the string"

'...more code

End Class


'Form2 code

Public Class Form2

Public str2 As开发者_StackOverflow社区 New string = ""

Private Sub Form2_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

str2 = Form1.str

End Sub

'...more code

End Class

Thank you in advance,

Tassos


You want to reference a specific instance of Form1, rather than use it's type name. I know VB.Net provides default instances for forms with the same name as the type name, but this is mainly for compatibility and feature parity with old vb6 code, and there are some good reasons not to use the default instances with .Net.

Additionally, most of the time you have a public field, you should use a property instead.


In form1 code..

put this in button code or something that you will use...

Form2.str2.Tostring = str.Tostring()

I hopes i give you idea....

0

精彩评论

暂无评论...
验证码 换一张
取 消