Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 734093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:19:56+00:00 2026-05-14T07:19:56+00:00

Hey all, i have a problem with trying to get 2 forms to close

  • 0

Hey all, i have a problem with trying to get 2 forms to close at different times using a timer on each of the 2 forms.

This is my form layout:

frmMain
Frm1
Frm2

Frm1 and Frm2 are identical to each other. FrmMain has 2 buttons on it. One button to call Frm1 and the other to call Frm2.

Frm1 and Frm2 each has a timer. It counts down to 0 and then does a .close(). However, if i pause between clicking the second button they both seem to always disappears at the same time.

I would do something like this…

Click on the first button (showing the Frm1 form)
wait about 10 secs…
Click on the second button (showing the Frm2 form)
they both are shown on screen…
then they both disappear at the same time…. which shouldn’t happen since i clicked the Frm2 box 10 seconds AFTER Frm1… So Frm1 should hide before Frm2 does…but it does not.

Any help to this problem would be great! 🙂

updated with code

Public Sub showMessageBox(ByVal typeOfBox As String, ByVal theMessage As String)
    If Form2.theNumOpened <= 6 Then
        Form2.theNumOpened = Form2.theNumOpened + 1 'ADDED

        Me.Opacity = 0
        Me.Show()

        Select Case Form2.theNumOpened
            Case 1
                Me.Text = "NBMsg1"
                Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 5)
            Case 2
                Me.Text = "NBMsg2"
                Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg1")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, Me.Height + 10, 0, 0, 1)
                Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 5)
            Case 3
                Me.Text = "NBMsg3"
                Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg2")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, Me.Height + 10, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg1")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 2) + 15, 0, 0, 1)
                Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 5)
            Case 4
                Me.Text = "NBMsg4"
                Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg3")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, Me.Height + 10, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg2")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 2) + 15, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg1")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 3) + 20, 0, 0, 1)
                Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 5)
            Case 5
                Me.Text = "NBMsg5"
                Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg4")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, Me.Height + 10, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg3")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 2) + 15, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg2")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 3) + 20, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg1")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 4) + 25, 0, 0, 1)
                Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 5)
            Case 6
                Me.Text = "NBMsg6"
                Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg5")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, Me.Height + 10, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg4")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 2) + 15, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg3")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 3) + 20, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg2")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 4) + 25, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg1")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 350, (Me.Height * 5) + 30, 0, 0, 1)
                Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 5)
            Case Else
                Me.Close()
                Me.Dispose()
        End Select

        isLoading = True
        theType = typeOfBox
        lblSaying.Text = theMessage

        If typeOfBox = "OK" Then
            Me.BackColor = Color.FromArgb(192, 255, 192)
        ElseIf typeOfBox = "ERR" Then
            Me.BackColor = Color.FromArgb(255, 192, 192)
        Else
            Me.BackColor = Color.FromArgb(255, 255, 192)
        End If

        If Len(theMessage) <= 30 Then
            howLong = 4000
        ElseIf Len(theMessage) >= 31 And Len(theMessage) <= 80 Then
            howLong = 7000
        ElseIf Len(theMessage) >= 81 And Len(theMessage) <= 100 Then
            howLong = 12000
        Else
            howLong = 17000
        End If

        Me.opacityTimer.Start()
    Else
        Me.Close()
    End If
End Sub

Private Sub opacityTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles opacityTimer.Tick
    If isLoading Then
        Me.Opacity += 0.07

        If Me.Opacity >= 0.8 Then
            Me.opacityTimer.Stop()
            Me.opacityTimer.Dispose()
            isLoading = False
            Pause(howLong)
            Me.opacityTimer.Start()
        End If
    Else
        Me.Opacity -= 0.08

        If Me.Opacity <= 0 Then
            Form2.theNumOpened = Form2.theNumOpened - 1 'ADDED
            Me.opacityTimer.Stop()
            Me.Close()
            Me.Dispose()
        End If
    End If
End Sub

Public Sub Pause(ByVal Milliseconds As Integer)
    Dim dTimer As Date

    dTimer = Now.AddMilliseconds(Milliseconds)

    Do While dTimer > Now
        Application.DoEvents()
    Loop
End Sub

And how i call it is like this:

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim theForm As New frmInfo2

    Call theForm.showMessageBox("MID", "This is just a simple test here! And some more text to see how longer it is." & theNum)
    theNum = theNum + 1
 End Sub

David

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:19:57+00:00Added an answer on May 14, 2026 at 7:19 am

    Got it by using this code:

    Private Enum FormState
        FadeIn
        Pause
        FadeOut
    End Enum
    
    Private Sub opacityTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles opacityTimer.Tick
        Select Case CurState
            Case FormState.FadeIn
                Me.Opacity += 0.07
    
                If Me.Opacity >= 0.8 Then
                    Me.opacityTimer.Stop()
                    CurState = FormState.Pause
                    PreviousInterval = opacityTimer.Interval
                    opacityTimer.Interval = howLong
                    Me.opacityTimer.Start()
                End If
    
            Case FormState.Pause
                Me.opacityTimer.Stop()
                CurState = FormState.FadeOut
                opacityTimer.Interval = PreviousInterval
                Me.opacityTimer.Start()
    
            Case FormState.FadeOut
                Me.Opacity -= 0.08
    
                If Me.Opacity <= 0 Then
                    Me.opacityTimer.Stop()
                    Form2.theNumOpened = Form2.theNumOpened - 1 'ADDED
                    Me.Close()
                    Me.Dispose()
                End If
        End Select
    End Sub
    

    :o)

    David

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.