zoukankan      html  css  js  c++  java
  • winform设计一个登录界面和修改密码的界面自动切换窗体(问题[已解] 望一起讨论)(技术改变世界cnblog)

    需求

    登录界面:

    1.要求 密码 文本可以显示和隐藏 字符 password属性     

    2.显示输入按钮button

    要求显示输入按钮 按下去之后,实现 名字变成“取消”,取消之后密码又是隐藏的

    3.要求只能输入错误 3次,3次之后自动退出

    4.要求点击修改密码 切换到 修改密码界面

    修改密码界面:

    1.要求 新密码 2次输入一致,并且不能和旧密码一样

    2.实现: 密码不能为空 提示     新旧密码一致 提示 自动清空     新密码2次输入不一致 提示并清空

    3.利用 ComboBox 控件实现, 利用  清除 按钮 清除 所在的行,(要求 如果不选择 comboBox,清除 按钮是不可使用的)

    问题在最后:

    登录界面:

    View Code
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using WindowsFormsApplication1;

    namespace WindowsFormsApplication6
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    int i = 3;
    private void btnLogin_Click(object sender, EventArgs e)
    {
    if (i == 0)
    {
    this.Close();
    }

    if (txtUsername.Text.ToLower() != "admin")
    {
    MessageBox.Show("用户名不存在");
    i--;
    return;
    }
    if (txtPassword.Text != "888888")
    {
    MessageBox.Show("密码错误");
    i--;
    return;
    }
    else
    {
    MessageBox.Show("登录成功","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
    }

    }

    private void Form1_Load(object sender, EventArgs e)
    {
    //txtPassword.PasswordChar = '*';
    txtPassword.UseSystemPasswordChar = true;
    }

    private void btnShow_Click(object sender, EventArgs e)
    {
    if (btnShow.Text== "显示输入")
    {
    txtPassword.UseSystemPasswordChar = false;
    btnShow.Text = "取消";
    return;
    }
    if (btnShow.Text == "取消")
    {
    txtPassword.UseSystemPasswordChar = true;
    btnShow.Text = "显示输入";
    return;
    }
    }

    private void btnChangePassword_Click(object sender, EventArgs e)
    {
    WindowsFormsApplication1.Form1 newForm1 = new WindowsFormsApplication1.Form1();
    newForm1.Show();//可以修改 前一个窗体
    //newForm1.ShowDialog();//要想修改前一个窗体必须关闭这个窗体



    }





    }
    }

    修改密码界面:

    View Code
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;


    namespace WindowsFormsApplication1
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
    button3.Enabled = true;
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;

    comboBox1.Items.Add("第一行");
    comboBox1.Items.Add("第二行");
    comboBox1.Items.Add("第三行");
    //comboBox1.SelectedIndex = 0;
    textBox1.UseSystemPasswordChar = true;
    textBox2.UseSystemPasswordChar = true;
    textBox3.UseSystemPasswordChar = true;
    button3.Enabled = false;

    }

    private void button2_Click(object sender, EventArgs e)
    {
    this.Close();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    if (textBox1.Text == string.Empty || textBox2.Text == string.Empty || textBox3.Text == string.Empty)
    {
    MessageBox.Show("密码不能为空");
    return;
    }
    if (textBox1.Text != "888888")
    {
    MessageBox.Show("旧密码不正确");
    textBox1.Clear();
    return;
    }
    if (textBox2.Text != textBox3.Text)
    {
    MessageBox.Show("2次新密码不一致");
    textBox2.Clear();
    textBox3.Clear();
    return;
    }
    if (textBox1.Text == textBox2.Text)
    {
    MessageBox.Show("新密码和原密码一样");
    textBox1.Clear();
    textBox2.Clear();
    textBox3.Clear();
    }


    }

    private void button3_Click(object sender, EventArgs e)
    {
    if (comboBox1.SelectedIndex==0)
    {
    textBox1.Clear();
    return;
    }
    if (comboBox1.SelectedIndex == 1)
    {
    textBox2.Clear();
    return;
    }
    if (comboBox1.SelectedIndex == 2)
    {
    textBox3.Clear();
    return;
    }

    }
    }
    }

    问题1: show() 与 showDialog()的区别,这个我给出答案

    答:show() 调用的时候,这个时候会出现 2个界面,登录和修改界面,并且 用户是可以修改父界面(登录界面的)

          showDialog()调用,是不可以修改父界面的,必须关闭 当前的子界面,也就是修改密码界面

    问题2:

    要实现 按“修改密码”按钮的时候的时候,调用修改密码界面并且隐藏 登录界面,当 ”修改密码界面“ 确定或者取消的时候,自动弹出 登录界面并且隐藏 修改密码界面。

    结论:对于 问题2

    我以前的做法是,为了实现弹出窗口,我是 建立了 2个  解决方案,其实没那个必要,在一个 解决方案里,生成多个Form1.cs即可

    这样类似于  多个类 继承于 Form

    感谢nfyz

    对于登录界面:

     private void btnChangePassword_Click(object sender, EventArgs e)
    {
    this.Visible = false;
                Form2 form2 = new Form2();
                form2.ShowDialog();
                this.Visible = true;
    }
    这样即可,当点击 修改密码 按钮就会隐藏 登录界面,然后打开了 修改密码界面,注意 这个时候 系统会停在这里,当你关闭 修改密码界面之后,登录界面又回来了。



  • 相关阅读:
    SQL Server 索引结构及其使用(三)
    SQL Server 索引结构及其使用(一)
    存储过程中的top+变量(downmoon)
    全文索引
    基本DDL 语句之Create Database(downmoon)
    SQL Server 索引结构及其使用(二)
    SQL Server 索引结构及其使用(四)
    前触发器和后触发器简介(downmoon)
    MongoDB学习笔记
    1. 索引的建立和运用
  • 原文地址:https://www.cnblogs.com/IAmBetter/p/2322156.html
Copyright © 2011-2022 走看看