我这有个以前给人做的Demo,大致如下: public enum IdentityState { NotLogin=0, Common, Middle, Super //Set user's other identities here }//Userinfo is to record user's info public struct UserInfo { public static string Username="";//Init value public static string Password=""; public static int nIdentity=0;//0: }/// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { //Show login window frmLogin myLogin=new frmLogin(); myLogin.ShowDialog();//Here change your state and save info if(UserInfo.nIdentity!=(int)IdentityState.NotLogin)//Loggin successfully { //Show main window frmMain myMain=new frmMain(); myMain.ShowDialog(); } }
{
FrmLogin frm=new FrmLogin();
frm.ShowDialog();
}
这样你处理完登录窗口后,住窗体才显示
你的(在主窗口的Load事件中,产生FrmLogin.)是不是FrmLogin frm =new FrmLogin()啊?
然后我用frm.close()还是没有能关掉原来的FrmLogin啊
public enum IdentityState
{
NotLogin=0,
Common,
Middle,
Super
//Set user's other identities here
}//Userinfo is to record user's info
public struct UserInfo
{
public static string Username="";//Init value
public static string Password="";
public static int nIdentity=0;//0:
}/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Show login window
frmLogin myLogin=new frmLogin();
myLogin.ShowDialog();//Here change your state and save info if(UserInfo.nIdentity!=(int)IdentityState.NotLogin)//Loggin successfully
{
//Show main window
frmMain myMain=new frmMain();
myMain.ShowDialog();
}
}
this.AddOwnedForm(mySubForm);
mySubForm.Owner = this;
这两句。否则,上面方法无效。你那两句话是在加在什么位置上面的???
{
FrmLogin f1=new FrmLogin();
f1.ShowDialog();
if(pass)
{ }
else
{
this.Dispose();
return;
}
}
程序先启动主窗体如果pass=true;
则主窗体打开,
否则主窗体关闭,程序关闭。
-------------------------------
http://www.cmsyp.com/pgfan
public static string username=null;
在主窗体的main函数中,把登录窗体显示为模式窗体,在登录成功后给username赋值,
在main函数中检测username的值,如果为null就return了,在程序中也可以访问username