C#上位机登录界面设计-账号注册、密码修改功能(三)

        C#上位机登录界面设计-界面跳转(二)是讲述的如何登入主界面,下一步是修改账号、密码及注册新的账号、密码。

C#上位机登录界面设计-界面设计(一)

C#上位机登录界面设计-界面跳转(二)

一、窗体设计

1、添加修改密码窗体

        右键点击右侧解决方案下面的项目名,弹出菜单“添加”-“Window窗体”,设置好新窗体信息后可新增窗体。

1.1、添加控件

在界面添加需要的控件,并设置属性值;

类型

命名

属性

属性值

Form

FormModify

text

修改密码

Label

Label1

Text

请输入密码:

Label

Label2

Text

再次输入:

Label

Label3

Text

Button

btnCModify

text

 确定修改

TextBox

txtPwd1

text

TextBox

txtPwd2

text

1.2、添加程序

双击按键,进入程序界面。

private void btnCModify_Click(object sender, EventArgs e)
{
    if (txtPwd1.Text != "")
    {
        if (txtPwd1.Text == txtPwd2.Text)
        {
            FormLogin.MIMA[FormLogin.x] = txtPwd1.Text;
            FormLogin fl = new FormLogin();
            this.Hide();
            fl.Show();
        }
        else
        {
            label3.Text = "两次密码输入不一致!请重新输入";
        }
    }
}

2、添加注册账号窗体

2.1、添加控件

在界面添加需要的控件,并设置属性值;

类型

命名

属性

属性值

Form

FormRAccount

text

注册账号

Label

Label1

Text

请输入账号:

Label

Label2

Text

请输入密码:

Label

Label3

Text

Button

button1

text

 确定

Buttonbutton2text返回

TextBox

txtAccount

text

TextBox

txtPwd

text

2.2、添加程序

a、双击确定按键,进入程序界面。

private void button1_Click(object sender, EventArgs e)
{
    int n = FormLogin.ZHANGHAO.Length;
    int j = 0;
    for (int i = 0; i < n; i++)
    {
        if (FormLogin.ZHANGHAO[i] == txtAccount.Text)
        {
            label3.Text = "该账号已被存在";
            label3.ForeColor = Color.Red;//错误显示红色
            return;
        }
        if (FormLogin.ZHANGHAO[i] != null)
        { j++; }
    }
    FormLogin.ZHANGHAO[j] = txtAccount.Text;
    FormLogin.MIMA[j] = txtPwd.Text;
    label3.Text = "注册成功";
    label3.ForeColor = Color.LimeGreen;//正确显示亮绿色
}

b、双击返回按键,进入程序界面。

private void button2_Click(object sender, EventArgs e)
{
    FormLogin fl = new FormLogin();
    this.Hide();
    fl.Show();
}

3、修改登录窗体

3.1、添加控件

在界面添加需要的控件,并设置属性值;

类型

命名

属性

属性值

ButtonbtnCPwd

text

修改密码

ButtonbtnRAccount

Text

注册账号

3.2、添加程序

a、双击修改密码按键,进入程序界面。

 private void btnCPwd_Click(object sender, EventArgs e)
 {
     FormModify fmm = new FormModify();

     this.Hide();

     fmm.Show();
 }

b、双击注册账号按键,进入程序界面。

private void btnRAccount_Click(object sender, EventArgs e)
{
    FormRAccount fra = new FormRAccount();

    this.Hide();

    fra.Show();
}

二、运行展示

三、完整程序

FormLogin.cs程序:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace 登录窗口实例
{
    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
        }

        
        //变量设置为公共全局静态变量
        public static string[] ZHANGHAO = new string[10];//初始用户名数组

        public static string[] MIMA = new string[10];//初始密码数组

        public static string SHOWME = "";
          

        public static int x = 0;
        
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtAccount.Text != "" && txtPwd.Text != "")
            {
                int n = ZHANGHAO.Length;
                SHOWME = txtAccount.Text;
                FormMain fm = new FormMain();
                for (int i = 0; i < n; i++)
                {
                    if (txtAccount.Text == ZHANGHAO[i])
                    {
                        if (txtPwd.Text == MIMA[i])
                        {
                            label1.Text = "欢迎使用本系统!";
                            label1.ForeColor = Color.LimeGreen;//正确显示亮绿色
                            btnCPwd.Visible = true;
                            this.Hide();
                            fm.Show();
                            x = i;
                        }
                        else
                        {
                            label1.Text = "密码错误,请重新输入";
                            label1.ForeColor = Color.Red;//错误显示红色
                        }
                    }
                    else
                    {
                        label1.Text = "账号错误,请重新输入";
                        label1.ForeColor = Color.Red;//错误显示红色
                     }
                }
            }
            else
            {
                label1.Text = "账号为空,请注册账号";
                label1.ForeColor = Color.Red;//错误显示红色
            }
        }

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

        private void btnCPwd_Click(object sender, EventArgs e)
        {
            FormModify fmm = new FormModify();

            this.Hide();

            fmm.Show();
        }

        private void btnRAccount_Click(object sender, EventArgs e)
        {
            FormRAccount fra = new FormRAccount();

            this.Hide();

            fra.Show();
        }
    }
}

FormMain.cs程序:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;

namespace 登录窗口实例
{
    public partial class FormMain : Form
    {
        
        public FormMain()
        {
            InitializeComponent();
            //textBox1.Text = FormLogin.ZHANGHAO[FormLogin.x];
            textBox1.Text = FormLogin.SHOWME;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FormLogin fl = new FormLogin();
            this.Hide();
            fl.Show();
        }
    }
}

FormModify.cs程序:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace 登录窗口实例
{
    public partial class FormModify : Form
    {
        public FormModify()
        {
            InitializeComponent();
        }

        private void btnCModify_Click(object sender, EventArgs e)
        {
            if (txtPwd1.Text != "")
            {
                if (txtPwd1.Text == txtPwd2.Text)
                {
                    FormLogin.MIMA[FormLogin.x] = txtPwd1.Text;
                    FormLogin fl = new FormLogin();
                    this.Hide();
                    fl.Show();
                }
                else
                {
                    label3.Text = "两次密码输入不一致!请重新输入";
                }
            }
        }
    }
}

FormRAccount.cs程序:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace 登录窗口实例
{
    public partial class FormRAccount : Form
    {
        public FormRAccount()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int n = FormLogin.ZHANGHAO.Length;
            int j = 0;
            for (int i = 0; i < n; i++)
            {
                if (FormLogin.ZHANGHAO[i] == txtAccount.Text)
                {
                    label3.Text = "该账号已被存在";
                    label3.ForeColor = Color.Red;//错误显示红色
                    return;
                }
                if (FormLogin.ZHANGHAO[i] != null)
                { j++; }
            }
            FormLogin.ZHANGHAO[j] = txtAccount.Text;
            FormLogin.MIMA[j] = txtPwd.Text;
            label3.Text = "注册成功";
            label3.ForeColor = Color.LimeGreen;//正确显示亮绿色
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FormLogin fl = new FormLogin();
            this.Hide();
            fl.Show();
        }
    }
}

  • 28
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值