|
-
Dec 5th, 2003, 06:40 PM
#1
Thread Starter
Member
Pause in a VB.NET code
Is there any method to simulate a pause in VB.NET ?
Or i have to use an empty For...Next ?
...because i think Timer is just for Forms, right ?
and what i want is to make a temporary pause in this code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim F As Decimal
For F = 0.00 To 1.00 Step 0.01
Me.Opacity = F
Me.Show()
' A pause here, to produce a more slower fade effect
Next F
End Sub
-
Dec 5th, 2003, 06:43 PM
#2
Frenzied Member
Look into System.Threading.Thread.Sleep - if I have that right - it pauses the current thread for the specified number of milliseconds.
Timers are not just for forms - there are three types - one optimized for forms. Do some searching and you'll find it.
-
Dec 6th, 2003, 05:17 PM
#3
Thread Starter
Member
Finally i got something.
Many thanks for those who tried to helped me.
Here is the code:
Imports Microsoft.VisualBasic.DateAndTime
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Sub Pause(ByVal Segundos_de_Pausa As Byte)
REM Faz uma pausa na execução da Aplicação.
REM A Função "Timer" pertence ao Módulo "Microsoft.VisualBasic.DateAndTime", e, indica o tempo decorrido desde a Meia-Noite.
Dim Tempo_Final As Double
Tempo_Final = Timer + Segundos_de_Pausa
Do While Timer < Tempo_Final
Loop
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
REM Carrega a "Form1" para a memória e para o ecrán.
Dim I As Double
Me.Show()
'Cria um Splash Screen com Fade In - Fade Out.
For I = 0 To 1 Step 0.01
Me.Opacity = I
Next I
Call Pause(5)
For I = 1 To 0 Step -0.01
Me.Opacity = I
Next I
Me.Hide()
Call Pause(2)
Me.BackgroundImage = Nothing
Me.BackColor = BackColor.SlateGray
Me.Show()
For I = 0 To 1 Step 0.01
Me.Opacity = I
Next I
End Sub
End Class
...and with just one Form and no Modules.
-
Dec 7th, 2003, 03:37 PM
#4
Addicted Member
Hi
Mike is right... and it's simple:
Thread.CurrentThread.Sleep(2000)
Alternatively, why not just activate a preset timer?
-
Dec 7th, 2003, 04:22 PM
#5
Thread Starter
Member
And how can i activate a preset timer, GSIV ?
-
Dec 7th, 2003, 04:40 PM
#6
you can do this easily , like so...
VB Code:
Private WithEvents tmr As Timer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tmr = New Timer()
tmr.Interval = 70
tmr.Start()
Me.Opacity = 0.01
End Sub
Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
If Not Me.Opacity = 1 Then
Me.Opacity += 0.01
Else
tmr.Stop()
End If
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Dec 7th, 2003, 04:44 PM
#7
Addicted Member
Just add a timer control to your application and set the interval, then enable or disable it it from your code, i.e.,
timTimer.Enabled = True.......... pause for the preset time
timTimer.Enabled = False......... disable timer
Or, you can do it all with code:
Imports System.Timers
Public Sub Delay()
Dim timTimer As System.Timers.Timer
timTimer = New System.Timers.Timer
timTimer.Interval = 1000
timTimer.Enabled = True
End sub
-
Dec 8th, 2003, 10:53 AM
#8
Thread Starter
Member
Ok many thanks guys
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|