2012-08-02 32 views
-3

我試圖在VB中翻譯這段代碼,但我無法弄清楚如何去做......任何人都可以告訴我翻譯過程如何?OpenNetCf - C#到VB

謝謝

private void WatchForDrives() 
{ 
    DeviceStatusMonitor monitor = new DeviceStatusMonitor(DeviceClass.FileSystem, false); 
    monitor.StartStatusMonitoring(); 
    monitor.DeviceNotification += delegate(object sender, DeviceNotificationArgs e) 
    { 
    string message = string.Format("Disk '{0}' has been {1}.", e.DeviceName,  e.DeviceAttached ? "inserted" : "removed"); 
    MessageBox.Show(message, "Disk Status"); 
    }; 
} 
+0

什麼版本的.NET?如果你做了簡單的谷歌搜索,轉換是相當微不足道的。 – Marlon 2012-08-02 16:07:03

+0

謝謝...我試過但不起作用。我使用的Compact框架3.5 – 2012-08-02 16:21:01

回答

1

只有VB 10支持多行lambda表達式,所以你必須創建一個單獨的方法來處理事件。這應該工作,無論編譯器:

Private Sub WatchForDrives() 
    Dim monitor As New DeviceStatusMonitor(DeviceClass.FileSystem, False) 
    monitor.StartStatusMonitoring() 
    AddHandler monitor.DeviceNotification, AddressOf MonitorDeviceNotified 
End Sub 

Private Sub MonitorDeviceNotified(ByVal sender As Object, ByVal e As DeviceNotificationArgs) 
    Dim message As String = String.Format("Disk '{0}' has been {1}.", e.DeviceName, If(e.DeviceAttached, "inserted", "removed")) 
    MessageBox.Show(message) 
End Sub 
+0

非常感謝你..完美的工作 – 2012-08-02 16:32:04

1

http://converter.telerik.com/

Private Sub WatchForDrives() 
    Dim monitor As New DeviceStatusMonitor(DeviceClass.FileSystem, False) 
    monitor.StartStatusMonitoring() 
    monitor.DeviceNotification += Function(sender As Object, e As DeviceNotificationArgs) Do 
     Dim message As String = String.Format("Disk '{0}' has been {1}.", e.DeviceName, If(e.DeviceAttached, "inserted", "removed")) 
     MessageBox.Show(message, "Disk Status") 
    End Function 
End Sub 
+0

謝謝,但它不工作...給「錯誤」後的錯誤 – 2012-08-02 16:18:27