读书人

给自定义组件内数组赋值请予以帮助

发布时间: 2013-02-17 10:44:46 作者: rapoo

给自定义组件内数组赋值,请予以帮助,谢谢!!!

给自定义组件内数组赋值,请予以帮助,谢谢!!!
该如何修改才能正常赋值,谢谢!!!


Public Class Form5
Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Table1.Col = 7
For i As Short = 0 To Table1.Col - 2
Table1.newlist1(i).Name = "GHH" & i‘运行时提示错误
Next
End Sub
End Class
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’

Public Class Table
Inherits Control
Public Structure NEWtableCell
Dim x1 As Single
Dim x2 As Single
Dim Name As String
End Structure
Private _Col As Short

Public Property Col() As Short
Get
Return _Col
End Get
Set(ByVal Value As Short)
_Col = Value
Refresh()
End Set

End Property
Public newlist1(Col) As NEWtableCell
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
For i = 0 To _Col
Debug.Print(newlist1(i).Name)
Next
End Sub
End Class

[解决办法]
Public Class Form5
Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Table1.Col = 7
For i As Short = 0 To Table1.Col - 2
Table1.newlist1(i).Name = "GHH" & i‘运行时提示错误
Next
End Sub
End Class
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’

Public Class Table
Inherits Control
Public Structure NEWtableCell
Dim x1 As Single
Dim x2 As Single
Dim Name As String
End Structure
Private _Col As Short

Public Property Col() As Short


Get
Return _Col
End Get
Set(ByVal Value As Short)
_Col = Value
'>>此处加上这些代码
if(_Col>0) THEN
newlist1=new NEWtableCell(_Col)
for i as short to _Col-1
newlist1(i)=new NEWtableCell()
next
end if
'<<此处加上这些代码
Refresh()
End Set

End Property
Public newlist1() As NEWtableCell '>>这句修改这样的
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
For i = 0 To _Col
Debug.Print(newlist1(i).Name)
Next
End Sub
End Class

读书人网 >VB Dotnet

热点推荐