How to make a please wait... form?

Shahab a 261 Reputation points
2022-11-28T15:53:43.58+00:00

Hi
I want to show the please wait... form along with the gif file when the software is processing the information to entertain the user.

Please help in this matter By Visual Basic .net

Developer technologies | VB
0 comments No comments
{count} votes

Accepted answer
  1. LesHay 7,141 Reputation points
    2022-11-28T16:41:43.793+00:00

    Hi
    Here is one example of hundreds of thousands possibilities.
    This is just an example, and no error checking.

    Form1 image and code below.
    Form2 (named PleaseWait) has a PictureBox1, and code below.
    A .gif image needs to be placed in a folder named 'Data' which is located in the same place as the executable (say Debug folder or Release folder depending on mode being used), and the file name edited in imPath variable to suit.
    The example uses a BackGroundWorker which stops the main Form from being blocked while PleaseWait is being shown.

    Form1

    264880-111.png

    Option Strict On  
    Option Explicit On  
    Imports System.ComponentModel  
    Public Class Form1  
      Dim WithEvents bgw As New BackgroundWorker  
      Dim PW As New PleaseWait  
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
        bgw.WorkerSupportsCancellation = True  
      End Sub  
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  
        ' show please wait form  
        If Not bgw.IsBusy Then  
          PW = New PleaseWait  
          PW.Show()  
          'start operation  
          bgw.RunWorkerAsync()  
        Else  
          ' user stopping operation  
          bgw.CancelAsync()  
        End If  
      End Sub  
      Private Sub bgw_DoWork(sender As Object, e As DoWorkEventArgs) Handles bgw.DoWork  
        ' this sub emulates some long  
        ' running operaion  
        Dim c As Integer = 0  
        Do  
          'show progress  
          Invoke(Sub() Label1.Text = c.ToString)  
      
          'emulate the operation with  
          ' a dummy 'pause'  
          Threading.Thread.Sleep(1000)  
      
          'increase counter  
          c += 1  
      
          ' stop if user cancels OR the  
          ' counter reaches limit  
        Loop Until bgw.CancellationPending Or c > 15  
      End Sub  
      Private Sub bgw_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles bgw.RunWorkerCompleted  
        ' stopped by user or counter  
        Label1.Text = "Stopped"  
      
        ' dispose of PleaseWait Form  
        PW.Dispose()  
      End Sub  
    End Class  
    

    EDIT: forgot the code for PleaseWait Form

    Option Strict On  
    Option Explicit On  
    Public Class PleaseWait  
      Dim imPath As String = IO.Path.Combine(Application.StartupPath, "Data", "Running.gif")  
      Private Sub PleaseWait_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
        PictureBox1.Image = Image.FromFile(imPath)  
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage  
      End Sub  
    End Class  
    
    3 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.