Gyzz我试图用只读列表(Of Points)属性创建一个用户控件。我在初始化和使用该属性时遇到问题!帮助我,我对视觉基础很陌生。使用只读列表属性
的UserControl1:
Public Class PointEntryPanel
Dim P as List(of PointF) = New List(Of PointF)
Public ReadOnly Property Points as List(Of PointF)
Get
P = Points
return P
End Get
End Property
End Class
形式:
Public Class Form1
Private Sub Form1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDoubleClick
ListBox1.Items.Add("You see ,No null reference exceptions")
ListBox1.Items.Add("I want a property just like this")
PointEntryPanel1.Points.Add(New PointF(0, 0)) 'While this creates exceptions
PointEntryPanel1.Points.Add(New PointF(1, 1)) 'And the point is not added to the PList
MessageBox.Show(PointEntryPanel1.PArray.ToString) 'this shows an empty box
End Sub
End Class
我想就像在列表框控件的 '商品' 属性的代码属性
是'PointEntryPanel1'中应该是'UserControl1'第二块是'PArray'应该正在使用“点数”?它如何不符合Magnus的答案? – Plutonix
是的,谢谢你通知它,这是一个错误!我得到一个空引用异常,并且这些点没有被“Points.Add”方法添加! –
'Dim P as List(of PointF)= New List(Of Points)'不会编译。如果你解决了这个问题,只是在返回中返回P,那么它就会正常工作 – Plutonix