首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

窗口有关问题,麻烦高手帮小弟我看看,

2012-03-21 
窗口问题,麻烦高手帮我看看,急....usingSystemusingSystem.Collections.GenericusingSystem.ComponentMo

窗口问题,麻烦高手帮我看看,急....
using   System;
using   System.Collections.Generic;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Text;
using   System.Windows.Forms;

namespace   Lg
{
        public   partial   class   Login   :   Form
        {
                //   public   static   bool   blCanLogin   =   false;
                  public   static   string   strUser   =   " ";
                  private   DataSet   ds   =   new   DataSet();
                  private   DataTable   myTable;
                  private   DataRow   myRow;
                  private   string   sendStrSQL   =   "select   *   from   LoginPwd ";

                public   Login()
                {
                        InitializeComponent();

                        DataBase   db   =   new   DataBase();
                        string   sendTableName   =   "LoginPwd ";
                        this.ds   =   db.SelectDataBase(sendStrSQL,sendTableName);
                        this.myTable   =   ds.Tables[0];
                }

                private   void   button2_Click(object   sender,   EventArgs   e)
                {
                        Application.Exit();
                }

                private   void   button1_Click(object   sender,   EventArgs   e)
                {
                        for   (int   i   =   0;   i   <   myTable.Rows.Count;   i++)
                        {
                                this.myRow   =   myTable.Rows[i];
                                if   (myRow[0].ToString().Trim()   ==   this.textBox1.Text.ToString().Trim()   &&   myRow[1].ToString().Trim()   ==   this.textBox2.Text.ToString().Trim())
                                {
                                        MessageBox.Show( "legal   user ");


                                        Form   MainUI   =   new   Form();             /////
                                        MainUI.Show();           /////
                                        return;
                                }
                                else
                                {
                                        MessageBox.Show( "illegal   user ");
                                        return;
                                }
                        }
                       
                       
                }
        }
}


当我打开主窗口后,我应该怎么把密码验证那个窗口关闭啊,我用THIS.CLOSE()全部窗口都关闭了,我记得我打开打开窗口的时候,好像旧的窗口会自动关闭的,

[解决办法]
把 Main() 中的 Application.Run(new Login()); 改成 Application.Run(new MainUI());

在 MainUI Load 事件中加载 Login...ShowDialog...验证时 Hide 验证后 Close...

因为主线程窗体 Close 会结束程序...新手常见问题...

ps:窗体命名不怎么规范...
[解决办法]
这个应该启动主窗口,登陆窗口只是在主窗口的构造函数中的直接New对象,然后登陆窗口以模式窗口打开,登陆成功就this.Close();失败就Application.Exit();
[解决办法]
登陆一般这样处理:登陆通过的时候返回DialogResult.ok,取消的返回DialogResult.Cancel.密码错误的时候返回DialogResult.None

例:
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
frmLogin fl = new frmLogin();
fl.ShowDialog();
if (fl.DialogResult == DialogResult.Cancel)
{
Application.Exit();
}
else
{
Application.Run(new frmMain());
}
}

热点排行