/// <summary> /// 完成初始化 /// </summary> protected virtual void PostInitialize() { if (ProgramConfiguration.Instance.OrderDlgCenterMainform) { UiUtility.PlaceFormAtCenter(this, show: false); } else { StartPosition = FormStartPosition.CenterScreen; } FormPlacementManager.Instance.Control(this); Layer = new MsgLayer(); Controls.Add(Layer); Layer.BringToFront(); //空格键快速提交 KeyDown += (s, e) => { if (SubmitButton?.Enabled == true && !InQueue) { if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Enter) { SubmitButton.PerformClick(); e.Handled = true; } } }; KeyPreview = true; }
public Login() { InitializeComponent(); _layer = new MsgLayer() { DlgSize = new Size(350, 150) }; Controls.Add(_layer); _layer.BringToFront(); Icon = Properties.Resources.icon_login; _service = AppContext.ExtensionManager.GlobalKernel.Resolve <ISessionLoginService>(); _service.StateChanged += (s, e) => ts.Text = _service.State; tc.VerifyCodeLoadComplete += (s, e) => { EnterReadyState(); }; tc.VerifyCodeLoadFailed += (s, e) => { tc.Enabled = true; ts.Image = Properties.Resources.tick_16; ts.Text = "被验证码无情地抛弃了..请刷新验证码"; }; tc.VerifyCodeEnterComplete += (s, e) => { CheckAndSubmit(); }; tc.EndAutoVc += (s, e) => { CheckAndSubmit(); }; tc.ResizeParent(this, ProgramConfiguration.Instance.CaptchaZoom); chkTmp.CheckedChanged += (s, e) => { cbRememberPwd.Enabled = !chkTmp.Checked; }; tsQrLogin.Click += (s, e) => { new QrLogin().Show(AppContext.HostForm); Close(); }; cbUserName.TextChanged += (s, e) => { var name = SelectedUserName; var pwd = UserKeyDataMap.Current[name].SelectValue(x => x.Password) ?? _session?.Password; if (string.IsNullOrEmpty(pwd)) { txtPassword.Text = ""; cbRememberPwd.Checked = false; txtPassword.Enabled = true; } else { txtPassword.Text = pwd; cbRememberPwd.Checked = true; AutoSubmitLogin(); } }; txtPassword.PasswordChar = Configuration.ProgramConfiguration.Instance.PasswordChar; Load += (s, e) => Prepare(); tsVirutalLogin.Click += (s, e) => { var user = SelectedUserName; if (user.IsNullOrEmpty()) { this.ShowToast("请选择一个已经登录过的用户。"); return; } if (txtPassword.TextLength == 0) { this.ShowToast("请输入登录密码"); return; } Session.OnUserLogined(new Session(user, false) { Password = txtPassword.Text }); Close(); }; FormClosing += (s, e) => { pbLogin.Image = null; }; }