积极答复者
请教,数组作为在组件内的属性,该如何做,谢谢!!!

问题
-
我想用newlist1作为组件的属性,还请帮助修改代码,谢谢!!!
Structure NEWtableCell Dim x1 As Single Dim x2 As Single Dim Name As String Dim Name1() As bleCell End Structure Public Structure bleCell Dim NEWtableCellBj As UserEnum Dim x1 As Single Dim x2 As Single Dim Name As String Dim cellcor As Color End Structure Private _Row As Integer = 1 Private _Col As Short = 1 Public Property Col() As Short Get Return _Col End Get Set(ByVal Value As Short) _Col = Value ReDim Preserve newlist1(Row) Invalidate() End Set End Property Public Property Row As Integer Get Return _Row End Get Set(ByVal value As Integer) _Row = value For i = 0 To Col - 1 ReDim Preserve newlist1(i).Name1(Row) Next Invalidate() End Set End Property Public newlist1() As NEWtableCell Public Property newlist() As NEWtableCell Get Return _newlist(1) End Get Set(ByVal value As NEWtableCell) _newlist(1) = value ' For i = 0 To Col - 1 'ReDim Preserve newlist1(i).Name1(Row) ' Next Invalidate() End Set End Property Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e) Me.DoubleBuffered = True e.Graphics.SmoothingMode = SmoothingMode.AntiAlias ' MsgBox(newlist1.Length) End Sub End Class
答案
-
可以,你参考:
Imports System.ComponentModel Public Class UserControl1 Private _users As List(Of User) = Nothing ''' <summary> ''' 自定义类 ''' </summary> <TypeConverter("ExpandableObjectConverter")> Public Class User <NotifyParentProperty(True)> Public Property ID As Integer = 0 <NotifyParentProperty(True)> Public Property Name As String = String.Empty End Class <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> <TypeConverter("CollectionConverter")> Public ReadOnly Property Users As List(Of User) Get If (_users Is Nothing) Then _users = New List(Of User) End If Return _users End Get End Property Private Sub UserControl1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class
- 已建议为答案 ThankfulHeartModerator 2013年2月9日 4:31
- 已标记为答案 Youen ZenModerator 2013年2月15日 9:36
全部回复
-
你究竟要完成什么功能呢?哪儿出错了?请给出具体信息,谢谢!
-
谢谢!!!不好意思,由于在家不能正常登陆论坛,不能正常回复,还请见谅。
我想求教的是:在组件的一个属性里,给newlist里的Name1添加维数(原有内容不变)或减少维数,并保存在组件里,谢谢!!!
Public Property newlist() As NEWtableCell Get Return _newlist(1) End Get Set(ByVal value As NEWtableCell) _newlist(1) = value ' For i = 0 To Col - 1 'ReDim Preserve newlist1(i).Name1(Row) ' Next Invalidate() End Set End Property
-
可以,你参考:
Imports System.ComponentModel Public Class UserControl1 Private _users As List(Of User) = Nothing ''' <summary> ''' 自定义类 ''' </summary> <TypeConverter("ExpandableObjectConverter")> Public Class User <NotifyParentProperty(True)> Public Property ID As Integer = 0 <NotifyParentProperty(True)> Public Property Name As String = String.Empty End Class <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> <TypeConverter("CollectionConverter")> Public ReadOnly Property Users As List(Of User) Get If (_users Is Nothing) Then _users = New List(Of User) End If Return _users End Get End Property Private Sub UserControl1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class
- 已建议为答案 ThankfulHeartModerator 2013年2月9日 4:31
- 已标记为答案 Youen ZenModerator 2013年2月15日 9:36