Public Class FrmAnneau
    Inherits System.Windows.Forms.Form

    Private mAnneau As NHenry.Scandir.ClsAnneau

#Region " Code généré par le Concepteur Windows Form "

    Public Sub New()
        MyBase.New()

        'Cet appel est requis par le Concepteur Windows Form.
        InitializeComponent()

        'Ajoutez une initialisation quelconque après l'appel InitializeComponent()

    End Sub

    'La méthode substituée Dispose du formulaire pour nettoyer la liste des composants.
    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

    'Requis par le Concepteur Windows Form
    Private components As System.ComponentModel.IContainer

    'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form
    'Elle peut être modifiée en utilisant le Concepteur Windows Form.  
    'Ne la modifiez pas en utilisant l'éditeur de code.
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents Timer2 As System.Windows.Forms.Timer
    Friend WithEvents Lst1 As System.Windows.Forms.ListBox
    Friend WithEvents Lst2 As System.Windows.Forms.ListBox
    Friend WithEvents CmdStartAnneau As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.Timer2 = New System.Windows.Forms.Timer(Me.components)
        Me.Lst1 = New System.Windows.Forms.ListBox
        Me.Lst2 = New System.Windows.Forms.ListBox
        Me.CmdStartAnneau = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Timer1
        '
        Me.Timer1.Interval = 600
        '
        'Timer2
        '
        Me.Timer2.Interval = 1000
        '
        'Lst1
        '
        Me.Lst1.Location = New System.Drawing.Point(2, 1)
        Me.Lst1.Name = "Lst1"
        Me.Lst1.Size = New System.Drawing.Size(154, 264)
        Me.Lst1.TabIndex = 0
        '
        'Lst2
        '
        Me.Lst2.Location = New System.Drawing.Point(200, 1)
        Me.Lst2.Name = "Lst2"
        Me.Lst2.Size = New System.Drawing.Size(168, 264)
        Me.Lst2.TabIndex = 1
        '
        'CmdStartAnneau
        '
        Me.CmdStartAnneau.Location = New System.Drawing.Point(12, 273)
        Me.CmdStartAnneau.Name = "CmdStartAnneau"
        Me.CmdStartAnneau.Size = New System.Drawing.Size(98, 22)
        Me.CmdStartAnneau.TabIndex = 2
        Me.CmdStartAnneau.Text = "&Start"
        '
        'FrmAnneau
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(529, 443)
        Me.Controls.Add(Me.CmdStartAnneau)
        Me.Controls.Add(Me.Lst2)
        Me.Controls.Add(Me.Lst1)
        Me.Name = "FrmAnneau"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Test anneau"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        mAnneau = New NHenry.Scandir.ClsAnneau(10)
        Timer1.Enabled = False
        Timer2.Enabled = True
        Randomize()
    End Sub

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        Timer1.Enabled = False
        Timer2.Enabled = False
        mAnneau = Nothing
    End Sub

    Private Sub CmdStartAnneau_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdStartAnneau.Click
        Timer1.Enabled = Not (Timer1.Enabled)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim mStr As String
        If IsNothing(mAnneau) Then Exit Sub
        mStr = CStr(Int(Rnd() * 1000))
        If mAnneau.AddItem(CType(mStr, String)) Then
            Lst1.Items.Add(mStr)
            Lst1.SelectedIndex = Lst1.Items.Count - 1
        Else
            Timer1.Enabled = False
        End If
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Dim mObj As Object
        If IsNothing(mAnneau) Then Exit Sub
        mObj = mAnneau.GetItem
        If IsNothing(mObj) = False Then
            Lst2.Items.Add(mObj)
            Lst2.SelectedIndex = Lst2.Items.Count - 1
        End If
        If Timer1.Enabled Then
            CmdStartAnneau.Text = "&Arreter"
        Else
            CmdStartAnneau.Text = "&Demarrer"
        End If
    End Sub
End Class
