学写一组件,定义了一数组,我想在设计模式下,调用组件的一个属性时,再给数组赋值。但在组件里如何能调用数组,谢谢!!!
Public Class MSTABE
Inherits Control
Private COL As Integer = 0
Public Structure NEWtable
Dim Row As Integer
Dim Col As Integer
Dim cell() As NEWtableCell
End Structure
Public Structure NEWtableCell
Dim NEWtableCellBj As UserEnum
Dim x1 As Single
Dim x2 As Single
Dim Name As String
End Structure
Public newlist1() As NEWtable
....
....
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
If Col = 0 Then Exit Sub
MsgBox(newlist1(0).cell(0).Name)'这句出错,该如何改,谢谢!!!
End Sub
End Class
'''''''''''''''''''''''''
Imports System.ComponentModel
Imports System.Drawing.Design
Public Class 列
Public _MyMstabae As New MSTABE
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
_MyMstabae.Col += 1
Col = _MyMstabae.Col
_MyMstabae.newlist1(0).Col = Col
ReDim Preserve _MyMstabae.newlist1(0).cell(Col-1)
_MyMstabae.newlist1(0).cell(Col - 1).Name = "Column1"
End Sub
End Class
------解决方案--------------------------------------------------------
报什么错?超出索引?
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
If Col = 0 Then Exit Sub
if ubound(newlist1)<0 orelse ubound(newlist1(0).cell)<0 then exit sub
MsgBox(newlist1(0).cell(0).Name)
End Sub
------解决方案--------------------------------------------------------
加个判断
If newlist1 IsNot Nothing AndAlso newlist1.Count > 0 Then
……
End If
或者用try catch
------解决方案--------------------------------------------------------