TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
richard.ryerson
NA
13
0
Control Container Problems
Nov 12 2004 12:10 PM
I don't have much experience creating custom controls and the like so please bear with me. I have a BaseControl which, for now, Inherits from a Label. I am extending a label by adding a collection of BaseControls (BaseControlCollection). This is a strong type collection inherited from CollectionBase. In the property browser the BaseControls property of my BaseControl shows up properly and I can open the CollectionEditor and create BaseControls. When I accept changes and close down the CollectionEditor i notice the new 'SubItems' of BaseControl is listed in the InitializeComponents sub of the form. However, there is no calls to add the sub items to the root BaseControls collection of BaseControls. Ie.. There isn't a call like: Me.BaseControl1.BaseControls.AddRange({Me.BaseControl2, Me.BaseControl3, etc...}) What am I missing? What am I doing wrong? Here is the code (BaseControl and BaseControlCollection): Imports System.ComponentModel.Design Imports System.ComponentModel Imports System.Drawing.Design Public Class BaseControl Inherits Label Private _baseControls As BaseControlCollection
_ Public Property BaseControls() As BaseControlCollection Get If _baseControls Is Nothing Then _baseControls = CreateBaseControlCollection() End If Return _baseControls End Get Set(ByVal Value As BaseControlCollection) _baseControls = Value End Set End Property Protected Overridable Function CreateBaseControlCollection() As BaseControlCollection Return New BaseControlCollection(Me) End Function End Class Public Class BaseControlCollection Inherits CollectionBase Public Event Changed As EventHandler Public Sub OnChanged(ByVal e As EventArgs) RaiseEvent Changed(Me, e) End Sub Private _owner As BaseControl Public Sub New(ByVal Owner As BaseControl) _owner = Owner End Sub Default Public Property Item(ByVal Index As Integer) As BaseControl Get Return CType(MyBase.List, BaseControl) End Get Set(ByVal Value As BaseControl) MyBase.List(Index) = Value OnChanged(EventArgs.Empty) End Set End Property Public Function Add(ByVal o As BaseControl) As Integer Return MyBase.List.Add(o) OnChanged(EventArgs.Empty) End Function Public Sub AddRange(ByVal c As ICollection) MyBase.InnerList.AddRange(c) OnChanged(EventArgs.Empty) End Sub Public Sub AddRange(ByVal c() As BaseControl) MyBase.InnerList.AddRange(c) OnChanged(EventArgs.Empty) End Sub Public Sub Insert(ByVal Index As Integer, ByVal o As BaseControl) MyBase.List.Insert(Index, o) OnChanged(EventArgs.Empty) End Sub Public Sub Remove(ByVal o As BaseControl) MyBase.List.Remove(o) OnChanged(EventArgs.Empty) End Sub Public Sub CopyTo(ByVal dest As Array, ByVal index As Integer) MyBase.List.CopyTo(dest, index) End Sub 'Public Sub Clear() ' MyBase.Clear() 'End Sub 'Public Sub RemoveAt(ByVal Index As Integer) ' 'MyBase.RemoveAt(Index) ' 'MyBase.InnerList.RemoveAt(Index) ' 'OnChanged(EventArgs.Empty) 'End Sub 'Public Overloads Overrides Function GetEnumerator() As IEnumerator ' Return MyBase.GetEnumerator 'End Function 'Public ReadOnly Property Count() As Integer ' Get ' Return MyBase.Count ' End Get 'End Property Public ReadOnly Property IsReadOnly() As Boolean Get Return MyBase.List.IsReadOnly End Get End Property Public ReadOnly Property IsFixedSize() As Boolean Get Return MyBase.List.IsFixedSize End Get End Property Public ReadOnly Property IsSyncronized() As Boolean Get Return MyBase.List.IsSynchronized End Get End Property Public ReadOnly Property SyncRoot() As BaseControlCollection Get Return Me End Get End Property Public ReadOnly Property IndexOf(ByVal o As BaseControl) As Integer Get Dim i As Integer = -1 For Each itm As BaseControl In MyBase.List i += 1 If itm.Name = o.Name Then Exit For End If Next Return i End Get End Property Public ReadOnly Property Contains(ByVal o As BaseControl) As Boolean Get For Each itm As BaseControl In MyBase.List If itm.Name = o.Name Then Return True End If Next End Get End Property End Class
Reply
Answers (
1
)
System.Diagnostics.DebuggerStepThrough()
Why does FontDialog.ShowColor not show the KnownColors?