private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     //Used to override the Close control box to minimize the form instead
     if (!RealClose)
     {
         e.Cancel         = true;
         HideMinimized    = true;
         this.WindowState = FormWindowState.Minimized;
     }
     else
     {
         //Check for currently Toggled Keys, if any, KeyUp them before changing profiles
         if (Bags.CheckForToggle())
         {
             DebugLog.Instance.writeLog("Found Keys currently pressed, Upping those keys", true);
             Bags.UpAllKeys();
         }
         DebugLog.Instance.closeFile();
     }
 }
        private void LoadButtonsfromProfile(string ProfileName)
        {
            //Check for currently Toggled Keys, if any, KeyUp them before changing profiles
            if (Bags.CheckForToggle())
            {
                DebugLog.Instance.writeLog("Found Keys currently pressed, Upping those keys", true);
                Bags.UpAllKeys();
            }

            //Load the Keymap from the .pgm file for this profile
            if (System.IO.File.Exists(Globals.ProfileSavePath + ProfileName + ".pgm"))
            {
                System.IO.FileStream fs = new System.IO.FileStream(Globals.ProfileSavePath + ProfileName + ".pgm", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Read);
                LoadFromStream(fs);
                mFileName = fs.Name;
                fs.Close();
                DebugLog.Instance.writeLog("Profile Keyset Loaded from profile: " + ProfileName, true);
            }
            else
            {
                //File doesn't exist, If application Active, Error to user, if not error to log file
                FormWindowState CurrentState = WindowState;
                if (CurrentState != FormWindowState.Minimized)
                {
                    //Form isn't minimized, popup message
                    if (ProfileName != DefGlobalProf)
                    {
                        MessageBox.Show("Error loading Key Mappings for profile " + ProfileName + ". Loading Defaults.", "", MessageBoxButtons.OK);
                    }
                    SaveButtonstoProfile(ProfileName);
                }
                else
                {
                    //Form is minimized, log error
                    DebugLog.Instance.writeLog("Error loading Key Mappings for profile " + ProfileName + ". Loading Defaults.", true);
                }
            }
        }