C#学习笔记(二十三)-- winForm练习3

1 登陆界面


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 登陆
{
    public partial class Form1 : Form
    {
        int misscount = 0; //使用类的字段,不能再委托函数中使用局部变量。

        public Form1()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {

            //int misscount = 0; //局部变量每次运行完毕变量的值会被销毁,而类的字段只要对象不销毁就一直存在。
            string username = textUserName.Text.Trim();
            string password = textPwd.Text;
            
            if (misscount > 2)
            {
                MessageBox.Show("错误次数过多,程序自动退出");
                Application.Exit();
            }
            if (username.Equals("admin",StringComparison.OrdinalIgnoreCase) && password == "8888")
            {
                MessageBox.Show("登陆成功");
            }
            else
            {
                MessageBox.Show("登陆失败");
                misscount++;
            }
        }
    }
}

2 输出最高成绩


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 输出最高成绩
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            int max = 0 ;
            int score = 0;
            string maxName = "";
            string maxScore = "";
            string[] lines = textChengji.Lines;
            try
            {
                foreach (string temp in lines)
                {
                    string[] strs = temp.Split('=');
                    string name = strs[0];
                    string strScore = strs[1];
                    score = Convert.ToInt32(strScore);

                    if (score > max)
                    {
                        max = score;
                        maxName = name;
                        maxScore = strScore;
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("输入有误");
                return;
            }


            textChengji.Text = "最高成绩获得者为" + maxName;
            textChengji.AppendText("\r\n最高成绩为" + maxScore);
        }
    }
}


3 combobox



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 comboBox示例
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {



            //comboBox 有三种dropdownStyle : dropDown 可以下拉与编辑,dropDownList 只可以下拉(常用)
            MessageBox.Show(Convert.ToString(comboBox1.SelectedIndex)); //序号
            MessageBox.Show(Convert.ToString(comboBox1.SelectedItem)); //选中的字


            //combox 在设计模式中点右键编辑项,可以编写下拉菜单
            comboBox1.Items.Clear();//清空旧数据
            if (!comboBox1.Items.Contains("长沙"))
            {
                comboBox1.Items.Add("长沙");
            }
           
          




        }
    }
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值