首页 > 其他分享 >label 多选 按钮 综合应用

label 多选 按钮 综合应用

时间:2022-09-26 11:35:10浏览次数:39  
标签:textuser 多选 Show Text System label 按钮 using net

环境介绍:

  • 代码工具: Visual Studio 2022
  • 开发框架: .net formwork 4.7.2

开发须知

当前我所了解的有.net core以及.net formwork两种框架
.net formwork:
这个是微软专用的框架,简单来说你所生成的可执行程序在其他电脑上是可以直接运行的,不需要安装环境,因为默认就已经有了。限制就是只能在windows上运行,根据选择的框架不同受限不同的windwos操作系统。默认高版本的.net formwork兼容低版本的.net formwork。

.net core:
这个框架适用于跨平台(windwos\linux\macos),但是前提是需要安装.net core的环境。简单来,如果你开发的可执行程序需要在其他电脑上运行,那么就必须在需要运行的电脑上安装.net core环境,要不然执行不了 -. -

创建项目

打开Visual Studio 准备创建项目
image

创建一个net formwork项目
image

配置窗体页面

image

窗体代码

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;

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

        private void buttonlogin_Click(object sender, EventArgs e)
        {
            // 登录前先验证有没有选择登录的类型
            if (radioteacher.Checked || radiostudent.Checked)
            {
                // 验证用户栏以及密码栏数据是否为空
                if (textuser.Text == String.Empty || textpwd.Text == String.Empty)
                {
                    if (textuser.Text == String.Empty)
                    {
                        MessageBox.Show("用户名为空");
                        textuser.Focus();
                    }
                    else
                    {
                        MessageBox.Show("密码为空");
                        textpwd.Focus();
                    }                
                }
                else {
                    if (radiostudent.Checked && textuser.Text == "student" && textpwd.Text == "student")
                    {

                        MessageBox.Show("学生登录成功");
                    }
                    else if (radioteacher.Checked && textuser.Text == "teacher" && textpwd.Text == "teacher")
                    {

                        MessageBox.Show("老师登录成功");
                    }
                    else {

                        MessageBox.Show("登录失败");
                        textuser.Clear();
                        // 清空密码框数据
                        textpwd.Clear();
                        // 光标指定到用户栏
                        textuser.Focus();
                    }
                }

            }
            else {
                MessageBox.Show("先选择登录类型");
                // 清空用户栏数据
                textuser.Clear();
                // 清空密码框数据
                textpwd.Clear();
                // 光标指定到用户栏
                textuser.Focus();
            }
        }
    }
}

标签:textuser,多选,Show,Text,System,label,按钮,using,net
From: https://www.cnblogs.com/shangcc205/p/16722704.html

相关文章