Added auto dis/connect based on having the focus

Added automatic connect & disconnect when the form gains and losses the
focus.