Results 1 to 4 of 4

Thread: checking a form has focus

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    checking a form has focus

    Hi.

    I have a form which calls another form on the click of a button and is then returned to when the called form is closed. On return to the original form I want to call some code that refreshes the original form but cannot find a way to only call that code once the original form is being returned to. At the moment it is calling that code as soon as the second form has been opened. Any help would be greatly appreciated!

    Code shown below:

    Private Sub buStaffDets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buStaffDets.Click
    gvar_IDToPass = coPropID.Text
    gvar_EditOrNewPerson = "Edit"
    gvar_theChkBox = "radStaff"
    Dim frmPersonDetails As New frmPersonDetails
    frmPersonDetails.Show()
    populateFields()
    End Sub

  2. #2
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: checking a form has focus

    You can use the form closed method of the second form:
    VB Code:
    1. Private Sub SecondForm_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
    2.         Dim frmPersonDetails As New frmPersonDetails
    3.         frmPersonDetails.Show()
    4.         populateFields()
    5. End Sub
    VB 2005, Win Xp Pro sp2

  3. #3
    Fanatic Member dom_stapleton's Avatar
    Join Date
    Sep 2005
    Location
    Leigh-on-Sea, UK
    Posts
    665

    Re: checking a form has focus

    Or you could try:

    VB Code:
    1. Private Sub buStaffDets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buStaffDets.Click
    2.       gvar_IDToPass = coPropID.Text
    3.       gvar_EditOrNewPerson = "Edit"
    4.       gvar_theChkBox = "radStaff"
    5.       Dim frmPersonDetails As New frmPersonDetails
    6.       frmPersonDetails.ShowDialog()
    7.       populateFields()
    8. End Sub

    This will open the new form as modal and the code after the frmPersonDetails.ShowDialog() line will not be run until the form is closed.
    I use Microsoft Visual Basic 2008 Express Edition.

    If my post has been helpful, please rate it, unless you don't believe in Karma... which actually I don't!

    Resources:
    Visual Basic Tutorials (1, 2) | MSDN Library | Google | Krugle | Search Forums

    Free components:
    Windows Forms Components | XP Common Controls Library

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: checking a form has focus

    Thanks for the advice both,

    I used the showdialog method which worked fine.

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