c#作业记录(03)--------分组框(GroupBox)

1) 综合运用label,button, textbox控件,设计密码登陆界面并调试其程序(可思考:如果用户名或者密码输错三次,自动退出,则程序代码如何编写)。示例图如下.
主要程序:

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 WindowsFormsApplication3
{
    
    public partial class Form1 : Form
    {
        public static int number=0;
        public Form1()
        {
            InitializeComponent();
        }

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

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox1.Focus();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "c#" || textBox1.Text == "C#")
            {
                if (textBox2.Text == "123456")
                    MessageBox.Show("登录成功");
                else
                {
                   
                    MessageBox.Show("密码错误");
                    number++;
                    if (number == 3)
                        this.Close();
                    textBox2.Text = "";
                    textBox2.Focus();
                }
            }
            else
            {
                
                MessageBox.Show("账号输入错误");
                number++;
                if (number == 3)
                    this.Close();
                textBox1.Text = "";
                textBox2.Text = "";
                textBox1.Focus();
            }
        }
    }
}

运行结果:c#作业记录(03)--------分组框(GroupBox)_第1张图片

2) 有两个分组框(GroupBox),分别为选择方式和显示方式,用来控制列表框中的选择方式,并把选中的信息在Lable控件中显示出来。如下图:
主要程序:

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

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            label1.Text = "";
            listBox1.SelectionMode = SelectionMode.None;
            if (radioButton1.Checked == true)
            {
                listBox1.SelectionMode = SelectionMode.None;
            }
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {
           
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            label1.Text = "";
            listBox1.SelectionMode = SelectionMode.None;
            if (radioButton2.Checked == true)
            {
                listBox1.SelectionMode = SelectionMode.One;
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            label1.Text = "";
            listBox1.SelectionMode = SelectionMode.None;
            if (radioButton3.Checked == true)
            {
                listBox1.SelectionMode = SelectionMode.MultiSimple;
            }
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            listBox1.SelectionMode = SelectionMode.None;
            if (radioButton4.Checked == true)
            {
                listBox1.SelectionMode = SelectionMode.MultiExtended;
            }
        }

        private void radioButton5_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton4.Checked == true)
            {
                listBox1.MultiColumn = false;
            }
        }

         private void radioButton6_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton6.Checked == true)
            {
                listBox1.MultiColumn = true;
            }
        }

         private void Form1_Load(object sender, EventArgs e)
         {

         }

         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
         {
             label1.Text = "";
             if (listBox1.SelectedIndices.Count == 1)
             {
                 label1.Text = listBox1.SelectedItem.ToString();
             }
             else
             {
                 for (int i = 0; i < listBox1.SelectedIndices.Count; i++)
                 {
                     label1.Text = label1.Text + listBox1.SelectedItems[i].ToString() + " ";   
                 }
             
             }
         }
    }
}

运行结果:
c#作业记录(03)--------分组框(GroupBox)_第2张图片

你可能感兴趣的:(c#作业记录(03)--------分组框(GroupBox))