好奇,以試圖在VB.net調試我的程序時,爲什麼我收到此錯誤獲取對象引用錯誤在VB.net
Object Reference not set to an instance of the object.
它說,我收到此錯誤是由於線路4和5:
Public Class Form1
Dim tSize
Dim S1 As String = ComboBox1.Text
Dim S2 As String = ComboBox2.Text
Private Sub FitContents()
tSize = TextRenderer.MeasureText(TextBox3.Text, TextBox3.Font)
TextBox3.Width = tSize.Width + 10
TextBox3.Height = tSize.Height
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = S1
TextBox2.Text = S2
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
Call FitContents()
End Sub
End Class
如果有人解釋爲什麼我收到這個錯誤我將非常感謝。
t大小沒有指定的類型。這是故意的嗎?我懷疑你沒有打開Option Strict。幫你一個忙,並把選項嚴格打開。 –