Results 1 to 8 of 8

Thread: Pause in a VB.NET code

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2003
    Location
    Portugal
    Posts
    49

    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

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2003
    Location
    Portugal
    Posts
    49
    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.

  4. #4
    Addicted Member GSIV's Avatar
    Join Date
    Jun 2002
    Location
    Texas, USA
    Posts
    213
    Hi

    Mike is right... and it's simple:
    Thread.CurrentThread.Sleep(2000)

    Alternatively, why not just activate a preset timer?

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2003
    Location
    Portugal
    Posts
    49
    And how can i activate a preset timer, GSIV ?

  6. #6
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you can do this easily , like so...
    VB Code:
    1. Private WithEvents tmr As Timer
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         tmr = New Timer()
    5.         tmr.Interval = 70
    6.         tmr.Start()
    7.         Me.Opacity = 0.01
    8.     End Sub
    9.  
    10.     Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
    11.         If Not Me.Opacity = 1 Then
    12.             Me.Opacity += 0.01
    13.         Else
    14.             tmr.Stop()
    15.         End If
    16.     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]

  7. #7
    Addicted Member GSIV's Avatar
    Join Date
    Jun 2002
    Location
    Texas, USA
    Posts
    213
    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

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2003
    Location
    Portugal
    Posts
    49
    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
  •  



Click Here to Expand Forum to Full Width