0

只是想弄清楚如何将一个简单的整数(StartingTeam)从 Form2 传递到 Form 1。

表格 2 代码

Public Class frmTeamChoose
Public StartingTeam As Integer
Public Sub btnTeam1_Click(sender As Object, e As EventArgs) Handles btnTeam1.Click
    StartingTeam = 1
End Sub

Public Sub btnTeam2_Click(sender As Object, e As EventArgs) Handles btnTeam2.Click
    StartingTeam = 2
End Sub

End Class

表格 1 称为表格 1

4

1 回答 1

1

虽然您需要提供更多信息,但我会尽力帮助您:
我想您已经从 Form1 打开了 Form2:

'In form1:
Dim k as integer=Form2.StartingTeam 

一个改进的解决方案是创建一个属性:
表格 2 代码:

 Private miStartingTeam 
 Public Property StartingTeam As Integer
    Get
        Return miStartingTeam 
    End Get
    Set(ByVal value As Integer)
        miStartingTeam = value
    End Set
 End Property

然后你的代码原样。
在表格 1 中:

'Open Form2
Dim f2 as new Form2
'f2.StartingTeam=1 'if you want to set a value before f2 opening
f2.Show


'Get StartingTeam from f2
dim k as integer=f2.StartingTeam 

需要帮助请叫我

于 2012-11-14T09:39:45.593 回答