如何不断检查网络驱动器是否存在?

时间:2017-03-17 19:30:03

标签: vb.net winforms animation scroll

我正在我的应用程序中不断运行检查,以检查网络驱动器是否每隔几秒就存在/可用。如果驱动器不存在,我想在我的应用程序顶部的面板内滚动文本标签,说明驱动器不可用或已断开连接。如何在重新检查之前检查驱动器是否存在并显示整个文本?这是我的代码:

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    Dim DrivePath As String = "C:\"
    If Not Directory.Exists(DrivePath) Then
        LabelText.AutoSize = True
        LabelText.Text = "Drive unavailable or disconnected."
        LabelText.Parent = PanelInfor
        LabelText.Location = New Point(PanelInfor.ClientSize.Width,
                                    PanelInfor.ClientSize.Height / 2 - (LabelText.Height / 2))
        Timer3.Start()

    End If
End Sub

Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
    If LabelText.Right < 0 Then
        LabelText.Left = PanelInfor.ClientSize.Width
    Else
        LabelText.Left -= 10
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

您的问题是您每次点击Timer2_Tick时都要重置标签的位置。

这应该可以解决您的问题

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick

    Dim DrivePath As String = "C:\"
    If Not Directory.Exists(DrivePath) Then
        LabelText.AutoSize = True
        LabelText.Text = "Drive unavailable or disconnected."
        LabelText.Parent = PanelInfor
        If (Not Timer3.Enabled) Then
            LabelText.Visible = True
            LabelText.Location = New Point(PanelInfor.ClientSize.Width,
                                    PanelInfor.ClientSize.Height / 2 - (LabelText.Height / 2))
            Timer3.Start()
        End If
    ElseIf Timer3.Enabled Then
        Timer3.Stop()
        LabelText.Visible = False
    End If

End Sub