2013-08-04 73 views
-1

下面的代碼允許我在打開和關閉時淡入淡出,這正是我想要的。不過,我希望我的表單在淡出開始之前保持10秒鐘。我正在努力完成該部分。設置時間後關閉表格

這是我到目前爲止有:

Public Class frmDefinitions 

    Private Sub Button1_Click(sender As Object, e As EventArgs) _ 
        Handles Button1.Click 
     tmr_out.Enabled = True 
    End Sub 

    Private Sub frmDefinitions_Load(sender As Object, e As EventArgs) _ 
        Handles MyBase.Load 
     Me.Opacity = 100 
     tmr_in.Enabled = True 
    End Sub 

    Private Sub tmr_in_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _ 
        Handles tmr_in.Tick 
     Me.Opacity += 0.05 
     If Me.Opacity = 1 Then 
      tmr_in.Enabled = False 
     End If 
    End Sub 

    Private Sub tmr_out_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _ 
        Handles tmr_out.Tick 
     Me.Opacity -= 0.05 
     If Me.Opacity = 0 Then 
      tmr_out.Enabled = False 
      Me.Close() 
     End If 
    End Sub 

End Class 
+0

你試過用計時器嗎?並且計時器滴答的事件處理程序將開始您的淡入淡出過程。 –

+0

我試着用兩個計時器,但我沒有成功。我一定是做錯了,加載後它仍然淡出。 –

+1

爲什麼你要將初始不透明度設置爲100,如果你不想淡入表單?不透明度的初始值是不是0? – Jaska

回答

2

您需要安裝第三Timer耽誤你的tmr_out Timer的開始。只要您的tmr_in被禁用,我會觸發延遲。然後,在開始淡出之前,您應該延遲10秒。您也可以嘗試使用表格的Shown事件來啓動延遲,但您需要調整10秒以適應淡入延遲。

Public Class Form1 
    Dim tmrDelay As New Timer() 

    Public Sub New() 
     InitializeComponent() 
     tmrDelay.Interval = 10000 
     AddHandler tmrDelay.Tick, AddressOf tmrDelay_Tick 
    End Sub 

    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load 
     Me.Opacity = 0 
     tmr_in.Enabled = True 
    End Sub 

    Private Sub tmrDelay_Tick(sender As System.Object, e As System.EventArgs) 
     tmrDelay.Stop() 
     tmr_out.Start() 
    End Sub 

    Private Sub tmr_in_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr_in.Tick 
     Me.Opacity += 0.05 
     If Me.Opacity = 1 Then 
      tmr_in.Enabled = False 
      tmrDelay.Start() 'Start Your 10 second delay here. 
     End If 
    End Sub 

    Private Sub tmr_out_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr_out.Tick 
     Me.Opacity -= 0.05 
     If Me.Opacity = 0 Then 
      tmr_out.Enabled = False 
      Me.Close() 
     End If 
    End Sub 


End Class 
+0

,很好的答案。謝謝。 –

+0

@JoseM。歡迎您,很高興有所幫助。 –