Okay, danke erst mal,
ich versuch es mal mit ein bisschen Quellcode:
Public Class FrmMain
Dim uForm As frmUSBBackup
Dim wForm As frmUSBWait
Private Sub btnToolStripBackup_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnToolStripBackup.Click
Dim erfolg As Boolean = False
Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
Dim d As DriveInfo
For Each d In allDrives
If d.DriveType = DriveType.Removable Then
If d.IsReady = True Then
erfolg = True
Exit For
End If
End If
Next
If erfolg = True Then
uForm = New frmUSBBackup()
uForm.ShowDialog()
Else
wForm = New frmUSBWait()
wForm.ShowDialog()
End If
End Sub
end class Folgende Form hat nur einen cancel button:
Public Class frmUSBWait
Private WithEvents myDriveWatcher As New DriveChangeWatcher()
Dim uForm As frmUSBBackup
Private Sub frmUSBWait_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Me.Left = FrmMain.Left + FrmMain.Width / 2 - Me.Width / 2
Me.Top = FrmMain.Top + FrmMain.Height / 2 - Me.Height / 2
End Sub
Private Sub myDriveWatcher_DriveCoutChanged(ByVal sender As Object, ByVal e _
As System.IO.DriveInfo) Handles myDriveWatcher.DriveArrived
uForm = New frmUSBBackup()
uForm.ShowDialog()
Me.Close()
End Sub
Private Sub myDriveWatcher_DriveRemoved(ByVal sender As Object, ByVal e As _
System.IO.DriveInfo) Handles myDriveWatcher.DriveRemoved
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
End Class 2.Form: einen Button "save", einen Button "cancel", ein paar textfelder, eine dirlistbox
Public Class frmUSBBackup
Private WithEvents myDriveWatcher As New DriveChangeWatcher()
Private Sub frmUSBBackup_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
Dim d As DriveInfo
Try
For Each d In allDrives
If d.DriveType = DriveType.Removable Then
If d.IsReady = True Then
txtName.Text = d.VolumeLabel
txtFilesystem.Text = d.DriveFormat
txtTotalSize.Text = Format(d.TotalSize / 1024 ^ 2, _
"#,##0")
txtUsedSpace.Text = Format((d.TotalSize - _
d.TotalFreeSpace) / 1024 ^ 2, "#,##0")
txtFreeSpace.Text = Format(d.TotalFreeSpace / 1024 ^ 2, _
"#,##0")
txtDrivePath.Text = d.Name & Format(Now.Date, _
"yyyyMMdd")
DirListBox1.Path = d.Name
Exit For
End If
End If
Next
Catch ex As Exception
End Try
End Sub
Private Sub myDriveWatcher_DriveRemoved(ByVal sender As Object, ByVal e As _
System.IO.DriveInfo) Handles myDriveWatcher.DriveRemoved
Me.Close()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnSave.Click
Try
CompressToUSB()
Catch ex As Exception
end try
End Sub Unter Win7 wird CompressToUSB garnicht erst ausgeführt. Messageboxen, die vor dem try bei btnSave.click gesetzt werden, kommen garnicht erst zur Ausführung. Irgendwie blockiert das gesamte Formular. Das Formular lässt sich eigentlich nur durch Ziehen des USB-Sticks schliessen.
Vielleicht hängt es auch damit zusammen, das ich die Klasse (von ActiveVB) von verschiedenen Formularen aus aufrufe. |