Public Class Form1 Inherits System.Windows.Forms.Form Dim Coll As New MyOwnClassCollection() #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Button2 As System.Windows.Forms.Button Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Friend WithEvents TextBox2 As System.Windows.Forms.TextBox Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Button3 As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button() Me.Button2 = New System.Windows.Forms.Button() Me.TextBox1 = New System.Windows.Forms.TextBox() Me.TextBox2 = New System.Windows.Forms.TextBox() Me.Label1 = New System.Windows.Forms.Label() Me.Label2 = New System.Windows.Forms.Label() Me.Button3 = New System.Windows.Forms.Button() Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(240, 136) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 0 Me.Button1.Text = "إضافة عنصر" ' 'Button2 ' Me.Button2.Location = New System.Drawing.Point(112, 136) Me.Button2.Name = "Button2" Me.Button2.TabIndex = 1 Me.Button2.Text = "حذف عنصر" ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(224, 64) Me.TextBox1.Name = "TextBox1" Me.TextBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes Me.TextBox1.Size = New System.Drawing.Size(168, 20) Me.TextBox1.TabIndex = 2 Me.TextBox1.Text = "" ' 'TextBox2 ' Me.TextBox2.Location = New System.Drawing.Point(40, 64) Me.TextBox2.Name = "TextBox2" Me.TextBox2.RightToLeft = System.Windows.Forms.RightToLeft.Yes Me.TextBox2.Size = New System.Drawing.Size(160, 20) Me.TextBox2.TabIndex = 3 Me.TextBox2.Text = "" ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(224, 24) Me.Label1.Name = "Label1" Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.Yes Me.Label1.TabIndex = 4 Me.Label1.Text = "اسم العنصر" ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(88, 24) Me.Label2.Name = "Label2" Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.Yes Me.Label2.TabIndex = 5 Me.Label2.Text = "رقم العنصر" ' 'Button3 ' Me.Button3.Location = New System.Drawing.Point(160, 184) Me.Button3.Name = "Button3" Me.Button3.Size = New System.Drawing.Size(104, 23) Me.Button3.TabIndex = 6 Me.Button3.Text = "عرض جميع العناصر" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(424, 226) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.Label2, Me.Label1, Me.TextBox2, Me.TextBox1, Me.Button2, Me.Button1}) Me.Name = "Form1" Me.Text = "l" Me.ResumeLayout(False) End Sub #End Region Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try Coll.Remove(CInt(TextBox2.Text)) TextBox1.Text = "" TextBox2.Text = "" Catch Exc As Exception MsgBox(Exc.Message) End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox1.Text = "" Then MessageBox.Show("اكتب اسم الخليّة أولا") Else Dim aWidget As New MyOwnClass() aWidget.Name = TextBox1.Text Coll.Add(aWidget) TextBox2.Text = (Coll.Count - 1).ToString() End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim counter As Integer For counter = 0 To Coll.Count - 1 MessageBox.Show(Coll.Item(counter).Name) Next End Sub End Class