testing if Form is active


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: testing if Form is active

  1. #1
    Join Date
    Mar 2005
    Posts
    29

    Question testing if Form is active

    I have a thread timer that works and calls a sub below, what I want the sub to do is refresh the form for the user. The issue I have is if the form isn't in focus (say the screensaver kicked on or you bring up another program or something) then the code crashes.

    When the timer expires it calls this sub

    Shared Sub CheckStatus(ByVal State As Object)
    Dim myform As Form

    myform = frmMain.ActiveForm
    myform.Activate()
    myform.Refresh()
    'MessageBox.Show("I am refreshed")
    myform = Nothing
    End Sub

    the problem is if frmMain is not the active form (because of screen saver or whatever) then myform doesn't get set and crashes when it tries to refresh it.
    My question is how can I test if frmMain is active and if it is refresh it if not go on doing whatever?

    Thanks

  2. #2
    Join Date
    May 2005
    Posts
    3
    Well, i'm a C# person, but just do a try and catch. If it fails, you know it's not active.

    Joel

  3. #3
    Join Date
    Mar 2005
    Posts
    29
    That worked so it wouldn't crash but is there a more elegant way to handle if the form is active?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center