1

我在我的对象中收到一个警告,它将值从一种形式转移到另一种形式 警告说 Button1 必须在 Object Form1 上调用 System.IDisposable.Dispose,然后才能对其进行引用

这是我在 button1 上的代码:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Form1 As New Form1
    Form1.a1 = TextBox1.Text
    Form1.a2 = TextBox2.Text
    Form1.a3 = TextBox3.Text
    Form1.a4 = TextBox4.Text
    Form1.a5 = TextBox5.Text
    Form1.a6 = TextBox6.Text
    Form1.a7 = TextBox7.Text
    Form1.a8 = TextBox8.Text
    Form1.a9 = TextBox9.Text
    Form1.a10 = TextBox10.Text
    Form1.Show()
    Form1.SetPrice()
    Me.Close()
End Sub

如何使用 System.IDisposable.Dispose?

4

1 回答 1

1

听起来列出的代码不在 Form1 中。无论它采用何种形式,都在实例化 Form1,但不处理它。只需将 Form1 包装在Using语句中:

Using Form1 As New Form1
    Form1.a1 = TextBox1.Text
    Form1.a2 = TextBox2.Text
    Form1.a3 = TextBox3.Text
    Form1.a4 = TextBox4.Text
    Form1.a5 = TextBox5.Text
    Form1.a6 = TextBox6.Text
    Form1.a7 = TextBox7.Text
    Form1.a8 = TextBox8.Text
    Form1.a9 = TextBox9.Text
    Form1.a10 = TextBox10.Text
    Form1.Show()
    Form1.SetPrice()
End Using
Me.Close()
于 2013-03-12T23:07:49.083 回答