读书人

自定义组件内数组赋值该怎么做多

发布时间: 2013-02-04 10:50:22 作者: rapoo

自定义组件内,数组赋值,该如何做,谢谢!!!
学写一组件,定义了一数组,我想在设计模式下,调用组件的一个属性时,再给数组赋值。但在组件里如何能调用数组,谢谢!!!



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
------解决方案--------------------


newlist1(0).cell(0)为null吧?
[解决办法]

if newlist1 is nothing orelse ubound(newlist1)<0 orelse newlist1(0).cell is nothing orelse ubound(newlist1(0).cell)<0 then exit sub

读书人网 >VB Dotnet

热点推荐