有没有办法消除散布式登录表单和主表单之间的延迟? [英] Is There a Way to Remove the Delay between an Interspersed Login form and the Main form?
问题描述
遵循建议此处在项目的Main方法中创建我的登录表单,如下所示:
Following the suggestion here to create my login form in the project's Main method like so:
[MTAThread]
static void Main()
{
AppDomain.CurrentDomain.UnhandledException += Unhandled;
frmLogin loginForm = new frmLogin();
if (loginForm.ShowDialog() != DialogResult.OK)
{
// If they hit "Close" just use the default values for now (for testing)
HHSConsts.userName = "duckbilled";
HHSConsts.pwd = "platypus";
HHSConsts.currentSiteNum = "Packers20Seahawks19";
}
else
{
HHSConsts.userName = loginForm.UserName;
HHSConsts.pwd = loginForm.Password;
HHSConsts.currentSiteNum = loginForm.SiteNumber;
}
loginForm.Dispose();
Application.Run(new frmMain());
}
登录表单具有两个按钮,确定"和关闭":
The login form has two buttons, "OK" and "Close":
private void buttonOK_Click(object sender, EventArgs e)
{
HHSConsts.userName = textBoxUsername.Text.Trim();
HHSConsts.pwd = textBoxPwd.Text.Trim();
HHSConsts.currentSiteNum = listBoxSitesWithFetchedData.SelectedItem.ToString();
// TODO: Prevent shutdown if "OK" is selected and there are any missing or bogus values?
this.Close();
}
private void buttonClose_Click(object sender, EventArgs e)
{
this.Close();
}
这很正常,但是在关闭登录表单和显示主表单之间存在一定的延迟.有没有办法缩小这个差距,以使间隔不太明显?
This works pretty fair, but there is a definite delay between the login form closing and the main form displaying. Is there a way to close this gap so that the interval is not so noticeable?
替换此:
Application.Run(new frmMain());
...与此:
Application.Run(new Form());
Program.cs中的
...结果如下:
...in Program.cs results in the following:
单击登录表单上的确定"按钮:应用程序关闭(主表单从不显示)
Clicking the OK button on the login form: app closes (main form never displays)
单击登录表单上的关闭"按钮:登录表单上的所有控件都消失了,但表单仍然存在...?!?
Clicking the Close button on the login form: all the controls on the login form disappear, but the form stays up...?!?
推荐答案
尝试尽可能多地预加载主表单:
Try pre-loading the main form with as much as you can:
[MTAThread]
static void Main()
{
var mainForm = new frmMain();
using(loginForm = new frmLogin())
{
if (loginForm.ShowDialog() != DialogResult.OK)
{
// If they hit "Close" just use the default values for now (for testing)
HHSConsts.userName = "duckbilled";
HHSConsts.pwd = "platypus";
HHSConsts.currentSiteNum = "Packers20Seahawks19";
}
else
{
HHSConsts.userName = loginForm.UserName;
HHSConsts.pwd = loginForm.Password;
HHSConsts.currentSiteNum = loginForm.SiteNumber;
}
}
mainForm.NotifyTheFormInstanceTheCredentialsHaveChangedIfItIsNotEventDrivenAlready();
Application.Run(mainForm);
}
这篇关于有没有办法消除散布式登录表单和主表单之间的延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!