Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //启动一个新进程对象,等待进程生成并进入空闲状态
                MyStartApp sa = new MyStartApp();
                appWin = sa.getHandle();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error: When process is created.");
            }

            // 把进程嵌入父窗口
            SetParent(appWin, this.Handle);
            // Remove border and whatnot
            SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE);
            // Move the window to overlay it on this window
            MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
        }
Example #2
0
        //点击确定按钮事件
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.cbBox_username.Text == "" || this.cbBox_username.Text == "<请输入账号>")
            {
                ToolTip tt = new ToolTip(); //实例化一个气泡对象
                tt.IsBalloon    = true;     //设置气泡对象的显示样式
                tt.ReshowDelay  = 100;      // 延迟时间
                tt.ShowAlways   = false;
                tt.AutoPopDelay = 100;
                tt.SetToolTip(this.cbBox_username, "请输入账号!"); //设定气泡内容及作用于哪个控件
                tt.Show("请输入账号!", this.cbBox_username);       //将气泡显示出来
                return;
            }

            if (this.tbBox_password.Text == "" || this.tbBox_password.Text == "<请输入密码>")
            {
                ToolTip tt = new ToolTip();
                tt.IsBalloon = true;   //设置气泡对象的显示样式
                tt.SetToolTip(this.tbBox_password, "请输入密码!");
                tt.Show("请输入密码!", this.tbBox_password);
                return;
            }

            if (!File.Exists("userInfo.exe"))
            {
                //users = new List<User>();  // 实例化对象
                                                                                                        //为了安全在这里创建了一个userInfo.exe文件(用户信息),也可以命名为其他的文件格式的(可以任意)
                FileStream      fs = new FileStream("userInfo.exe", FileMode.Create, FileAccess.Write); //创建一个文件流对象
                BinaryFormatter bf = new BinaryFormatter();                                             //创建一个序列化和反序列化对象

                //将下拉框的登录名先保存在变量中, 加密并保存在本地
                string loginName = this.cbBox_username.Text.Trim();
                string loginPswd = this.tbBox_password.Text.Trim();

                for (int i = 0; i < this.cbBox_username.Items.Count; i++)     // 遍历下拉框中的所有元素
                {
                    if (this.cbBox_username.Items[i].ToString() == loginName) // 防止重复
                    {
                        this.cbBox_username.Items.RemoveAt(i);                //如果当前登录用户在下拉列表中已经存在,则将其移除
                        break;
                    }
                }

                for (int i = 0; i < users.Count; i++)    //遍历用户集合中的所有元素
                {
                    if (users[i].LoginName == loginName) //如果当前登录用户在用户集合中已经存在,则将其移除
                    {
                        users.RemoveAt(i);
                        break;
                    }
                }


                //每次都将最后一个登录的用户放插入到第一位
                this.cbBox_username.Items.Insert(0, loginName);
                User user;
                if (this.ckBox_login.Checked == true)                            //如果用户要求要记住密码
                {
                    user = new User(loginName, MyEncrypt.EncryptDES(loginPswd)); //将登录ID和密码一起插入到用户集合中
                }
                else
                {
                    user = new User(loginName, ""); //否则只插入一个用户名到用户集合中,密码设为空
                }
                users.Insert(0, user);              //在用户集合中插入一个用户
                cbBox_username.SelectedIndex = 0;   //让下拉框选中集合中的第一个

                bf.Serialize(fs, users);            //将可序列化User用户类对象集合写入到硬盘中
            }


            //返回OK, 显示App窗体
            //启动一个新进程对象,等待进程生成并进入空闲状态
            MyStartApp sa = new MyStartApp();

            sa.getHandle();

            //以下开始显示主窗体 并关闭登录窗体
            this.DialogResult = DialogResult.OK;
            this.Close();
        }