I have an arrayList in which I put objects (objects containing some connected lines and a pen)
then I draw all the objects from the arrayList.
Now, I want to make an arraylist of arrayLists (every curve with 400 connected lines is in an arrayList)
This way I would be able to draw any specific curve I wish, instead of drawing them all.
Notice that both the ArrayList and the collection of arrayLists need to be dynamic(so I can add to it)
Any idea?
Here is my idea:
Public Curves As ArrayList
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ACurveObject As New ArrayList
ACurveObject.Add(New LineObject(New Point(x1, y1), New Point(x2, y2)))
Curves.Add(ACurveObject)
End Sub
Regards,
{pseudocode} / {Time} ± ¼*ƒ(Me.Thoughts÷3)^² = Idle »(°_°)« Mind
' --------------------------
' Module1
' --------------------------
Module Module1
Public Interface GraphObject
Sub Paint(ByRef g As Graphics)
End Interface
Public Class LineObject
Implements GraphObject
Private pointA As Point
Private pointB As Point
Public Sub New(ByVal ptA As Point, ByVal ptB As Point)
pointA = ptA
pointB = ptB
End Sub
Public Sub Paint(ByRef g As Graphics) Implements GraphObject.Paint
g.DrawLine(Pens.Black, pointA, pointB)
End Sub
End Class
Public Class ClassCurves
Implements GraphObject
Public ID As String
Public CurvesCollection As ArrayList = New ArrayList
Public Overrides Function toString() As String
Return "Curve #" & ID
End Function
Public Sub Paint(ByRef g As System.Drawing.Graphics) Implements GraphObject.Paint
Dim lo As LineObject
For Each lo In CurvesCollection
lo.Paint(g)
Next
End Sub
End Class
End Module
' --------------------------
' Form1
' --------------------------
Public Class Form1
Inherits System.Windows.Forms.Form
#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.ICon
'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.Butto
Friend WithEvents PictureBox1 As System.Windows.Forms.Pictu
Friend WithEvents CheckedListBox1 As System.Windows.Forms.Check
<System.Diagnostics.Debugg
Me.Button1 = New System.Windows.Forms.Butto
Me.PictureBox1 = New System.Windows.Forms.Pictu
Me.CheckedListBox1 = New System.Windows.Forms.Check
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Anchor = CType((System.Windows.Form
Me.Button1.Location = New System.Drawing.Point(16, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(120, 72)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Make a new collection of lines collection containing 100 objects in each"
'
'PictureBox1
'
Me.PictureBox1.Anchor = CType((((System.Windows.Fo
Or System.Windows.Forms.Ancho
Or System.Windows.Forms.Ancho
Me.PictureBox1.BackColor = System.Drawing.Color.White
Me.PictureBox1.BorderStyle
Me.PictureBox1.Location = New System.Drawing.Point(24, 16)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(552, 240)
Me.PictureBox1.TabIndex = 1
Me.PictureBox1.TabStop = False
'
'CheckedListBox1
'
Me.CheckedListBox1.Anchor = CType(((System.Windows.For
Or System.Windows.Forms.Ancho
Me.CheckedListBox1.BorderS
Me.CheckedListBox1.CheckOn
Me.CheckedListBox1.Locatio
Me.CheckedListBox1.Name = "CheckedListBox1"
Me.CheckedListBox1.Size = New System.Drawing.Size(424, 92)
Me.CheckedListBox1.TabInde
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(584, 382)
Me.Controls.Add(Me.Checked
Me.Controls.Add(Me.Picture
Me.Controls.Add(Me.Button1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private rnd As New Random(DateTime.Now().Seco
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim curve As ClassCurves = New ClassCurves
curve.ID = CheckedListBox1.Items.Coun
Dim x1, y1, x2, y2 As Integer
For num As Short = 1 To 100
x1 = rnd.NextDouble() * PictureBox1.Width
y1 = rnd.NextDouble() * PictureBox1.Height
x2 = rnd.NextDouble() * PictureBox1.Width
y2 = rnd.NextDouble() * PictureBox1.Height
curve.CurvesCollection.Add
Next num
CheckedListBox1.Items.Add(
PictureBox1.Refresh()
End Sub
Private Sub CheckedListBox1_SelectedIn
PictureBox1.Refresh()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.Paint
Dim go As GraphObject
e.Graphics.Clear(PictureBo
For Each go In CheckedListBox1.CheckedIte
go.Paint(e.Graphics)
Next
End Sub
End Class