Schau Dir das mal an .....
Eine genaue Bestimung der Dauer eines
Kopiervorgangs ist nicht möglich.
Man kann nur eine Abschätzung machen: aus
dem benötigten Zeitbedarf für die bereits
kopierten Bytes.
Der Beispielcode besteht aus zwei Teilen,
die beide zusammen in ein WinForms-Formular einzutragen
sind.
Teil 1 .....
Imports System.IO
Public Class frmBackup
Dim w As Integer = 380
Dim WithEvents btnSource As New Button With _
{.Parent = Me, .Text = "Quelle", .Width = w}
Dim WithEvents btnDest As New Button With _
{.Parent = Me, .Text = "Ziel", .Width = w, .Top = 50}
Dim WithEvents btnAction As New Button With _
{.Parent = Me, .Text = "Sichern", .Top = 100, .Left = 150}
Dim prg As New ProgressBar With _
{.Parent = Me, .Top = 150, .Width = w, .Minimum = 0}
Dim lblInfo As New Label With _
{.Parent = Me, .Width = w, .Top = 200, .Text = ""}
Dim lblTime As New Label With _
{.Parent = Me, .Width = w, .Top = 250}
Dim fbd As New FolderBrowserDialog
'Variable für den Info-Delegaten
Dim progress_value, progress_maximum As Integer
Dim bedarf_alt As Long
Dim infotext As String, headline As String
'Info-Delegat
Dim SetinfoDelegate As New MethodInvoker(AddressOf SetInfo)
Private Sub frmBackup_Load(sender As Object, _
e As EventArgs) Handles MyBase.Load
Me.Size = New Size(400, 300)
Me.FormBorderStyle = FormBorderStyle.FixedSingle
End Sub
Private Sub btnSource_Click(sender As Object, _
e As EventArgs) Handles btnSource.Click
With fbd
.Description = "zu sichernder Ordner"
.ShowNewFolderButton = False
If .ShowDialog = DialogResult.Cancel Then Exit Sub
btnSource.Text = .SelectedPath
End With
End Sub
Private Sub btnDest_Click(sender As Object, _
e As EventArgs) Handles btnDest.Click
With fbd
.Description = "Backup-Ordner"
.ShowNewFolderButton = True
If .ShowDialog = DialogResult.Cancel Then Exit Sub
btnDest.Text = .SelectedPath
End With
End Sub
Private Sub btnAction_Click(sender As Object, _
e As EventArgs) Handles btnAction.Click
'Thread für den Kopiervorgang erstellen und starten
Dim copythread As New Threading.Thread(AddressOf SaveFiles)
copythread.Start()
End Sub
Private Sub SetInfo()
'Benutzeroberfläche während des Kopierens
'per Invoke aktualisieren
prg.Maximum = progress_maximum
prg.Value = progress_value
lblTime.Text = infotext
lblInfo.Text = headline
Me.Invalidate()
End Sub
'... ab hier Teil 2 einfügen
Beitrag wurde zuletzt am 15.12.12 um 07:28:38 editiert. |