' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Windows.Forms

Public Class MainForm
Inherits Form
    Private status As Label
    Private start As Button
    Private abort As Button
    Private t As Timer

    Public Sub New()
        status = New Label
        start = New Button 
        abort = New Button 
        SuspendLayout
        status.Location = New Point(50, 50)
        status.Size = New Size(200, 50)
        status.Name = "Status TextBox"
        status.Font = New Font(FontFamily.GenericSerif, 24.0)
        status.Text = "Stopped"
        status.ForeColor = Color.Red
        start.Location = New Point (50, 150)
        start.Size = New Size (200, 50)
        start.Name = "Start Button"
        start.Text = "Start"
        AddHandler start.Click, AddressOf StartClick
        abort.Location = New Point (50, 250)
        abort.Size = New Size (200, 50)
        abort.Name = "Abort Button"
        abort.Text = "Abort"
        AddHandler abort.Click, AddressOf AbortClick
        ClientSize = New Size (300, 350)
        Controls.Add(status)
        Controls.Add(start)
        Controls.Add(abort)
        Name = "Main Form"
        Text = "Main Form"
        ResumeLayout(False)
        t = New Timer
        t.Interval = 60 * 1000
        AddHandler t.Tick, AddressOf DoIt
    End Sub
    
    Private Sub XCopy(dir1 As String, dir2 As String)
        Dim files As String() = Directory.GetFiles(dir1)
        For Each f As String In files
            File.Copy(f, dir2 & f.Substring(dir1.Length), True)
        Next
        Dim dirs As String() = Directory.GetDirectories(dir1)
        For Each d As String In dirs
            XCopy(d, dir2 & d.Substring(dir1.Length))
        Next
    End Sub

    Private Sub DoIt(ByVal sender As Object, ByVal e As EventArgs)
        XCopy("C:\fra", "C:\til")
    End Sub

    Private Sub StartClick(ByVal sender As Object, ByVal e As EventArgs)
        t.Start
        status.Text = "Started"
        status.ForeColor = Color.Green
    End Sub

    Private Sub AbortClick(ByVal sender As Object, ByVal e As EventArgs)
        t.Stop
        status.Text = "Stopped"
        status.ForeColor = Color.Red
    End Sub

    <STAThread()> _
    Public Shared Sub Main(ByVal args As String())
        Application.Run(New MainForm )
        Application.Exit
        Environment.Exit(0)
    End Sub
End Class 
