我的登录窗体是要写成DLL组件的,而主窗体是EXE形式的。现在要做个登录验证程序。
请问我的登录窗体DLL中该如何做才能通知主窗体登录是否成功?

解决方案 »

  1.   

    在登录窗口的类里面做一个标识是否登录成功的公共属性,或者直接用它的DialogResult属性 或者直接在dll里面封装一个登录方法,返回bool
      

  2.   

    frmLogin frm = new frmLogin();
    frmMain frmMain = new frmMain();
    DialogResult dt =frm.ShowDialog();
    if(dt == DialogResult.OK)
    {
        Application.Run(frmMain);
    }
      

  3.   

    那是先让主窗体HIDE再显示登陆窗体好,还是先显示登录窗体,验证成功后再显示主窗体好呢?
      

  4.   

    我的做法是让主窗体在LOAD中隐藏掉,再显示登录窗体,之后再验证显示。但是这样会有麻烦,就是不好传是否登录成功标示
      

  5.   

    在Main 方法里面,首先显示登陆窗体,如果用户合法,再show 主窗体
      

  6.   

    用泛型做成单窗体模式,dll的返回值指示验证是否成功很容易吧?
      

  7.   

    为什么不把主窗体做成容器呢,MDI
      

  8.   

      static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                frmLogin frm = new frmLogin();
                using (frm)
                {
                    if (frm.ShowDialog() == DialogResult.OK)//内容验证密码通过this.DialogResult=DialogResult.OK; this.close(); 
                    {
                        Application.Run(new frmMain(frm.userid, frm.power));
                        frm.Dispose();
                    }
                }
                
            }
        }
    我一般是这样的
      

  9.   

    一般我的做法。。
    FormMian代码(主窗体)using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace System
    {
        public partial class FormMain : Form
        {
            public FormMain()
            {
                InitializeComponent();
            }        private void FormMain_Load(object sender, EventArgs e)
            {
                FormLogin fl = new FormLogin();
                bool Logined=false;
                do
                {
                    if (fl.ShowDialog(this) == DialogResult.OK)
                    {
                        string u = "u";
                        string p = "p";
                        if (fl.UserID == u && fl.UserPwd == p)
                        {
                            Logined = true;
                            fl.Close();
                        }
                        else
                        {
                            MessageBox.Show("非法登陆", "管理员登陆", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }                }
                    else
                    {
                        this.Close();
                    }
                }
                while(!Logined&&(fl.DialogResult==DialogResult.OK));
            }
        }
    }二:FormLogin代码(验证窗体)
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace System
    {
        public partial class FormLogin : Form
        {
            public FormLogin()
            {
                InitializeComponent();
            }        private void btnExit_Click(object sender, EventArgs e)
            {
                Application.Exit();//exit
            }
            public String UserID
            {
                get { return tbUserID.Text; }
            }
            public String UserPwd
            {
                get { return tbUserPwd.Text; }
            }
        }
    }在这个窗体中要注意的是设置登陆按钮btnLogin的DialogResult属性为OK
    你那个DLL的没做过~