Exemplo n.º 1
0
        private void SignInForm_Activated(object sender, EventArgs e)
        {
            // force window to have focus
            // please refer http://stackoverflow.com/questions/278237/keep-window-on-top-and-steal-focus-in-winforms
            uint foreThread = Win32Helper.GetWindowThreadProcessId(Win32Helper.GetForegroundWindow(), IntPtr.Zero);
            uint appThread  = Win32Helper.GetCurrentThreadId();

            //const uint SW_SHOW = 5;
            if (foreThread != appThread)
            {
                Win32Helper.AttachThreadInput(foreThread, appThread, true);
                Win32Helper.BringWindowToTop(this.Handle);
                //ShowWindow(this.Handle, SW_SHOW);
                Win32Helper.AttachThreadInput(foreThread, appThread, false);
            }
            else
            {
                Win32Helper.BringWindowToTop(this.Handle);
                //ShowWindow(this.Handle, SW_SHOW);
            }
        }
Exemplo n.º 2
0
        private void GotoTabPage(TabPage tabpage, UserLoginSetting userlogin)
        {
            if (m_SignUpDialog != null)
            {
                m_SignUpDialog.Dispose();
                m_SignUpDialog = null;
            }

            tabControl.SelectedTab = tabpage;

            if (this.WindowState == FormWindowState.Minimized)
            {
                this.WindowState   = FormWindowState.Normal;
                this.ShowInTaskbar = true;
            }

            uint foreThread = Win32Helper.GetWindowThreadProcessId(Win32Helper.GetForegroundWindow(), IntPtr.Zero);
            uint appThread  = Win32Helper.GetCurrentThreadId();

            if (foreThread != appThread)
            {
                Win32Helper.AttachThreadInput(foreThread, appThread, true);
                Win32Helper.BringWindowToTop(this.Handle);
                Show();
                Win32Helper.AttachThreadInput(foreThread, appThread, false);
            }
            else
            {
                Win32Helper.BringWindowToTop(this.Handle);
                Show();
            }
            Activate();

            if (tabpage == tabSignIn)
            {
                if (userlogin == null)
                {
                    cmbEmail.Text               = string.Empty;
                    iscmbEmailFirstChanged      = false;
                    txtPassword.Text            = string.Empty;
                    chkRememberPassword.Checked = false;
                }
                else
                {
                    cmbEmail.Text          = userlogin.Email;
                    iscmbEmailFirstChanged = true;
                    if (userlogin.RememberPassword)
                    {
                        txtPassword.Text = SecurityHelper.DecryptPassword(userlogin.Password);
                    }
                    else
                    {
                        txtPassword.Text = string.Empty;
                    }
                    chkRememberPassword.Checked = userlogin.RememberPassword;
                }

                if (string.IsNullOrEmpty(cmbEmail.Text))
                {
                    cmbEmail.Select();
                }
                else if (string.IsNullOrEmpty(txtPassword.Text))
                {
                    txtPassword.Select();
                }
                else
                {
                    btnSignIn.Select();
                }

                this.AcceptButton = btnSignIn;
            }
            else if (tabpage == tabMainStationSetup)
            {
                btnOK.Tag = userlogin;
                btnOK.Select();
                this.AcceptButton = btnOK;
            }
        }