1.创建Windows窗体应用程序,实现用户登录功能,当输入正确与错误时均给出相应的提示信息,规定用户输入错误次数不能超过3次。(源代码+运行界面)
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 Form1()
{
InitializeComponent();
}
private static int n = 0;
private void button1_Click(object sender, EventArgs e)
{
if (n == 3)
{
MessageBox.Show("次数已用完!");
Close();
}
if ((textBox1.Text == "Frozen1") && (textBox2.Text == "Frozen2"))
{
MessageBox.Show("登陆成功!", "登陆成功");
}
else
{
MessageBox.Show("用户名或密码错误", "登陆失败" );
n++;
}
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
}
}
2. 创建Windows窗体应用程序,界面如下所示,当在组合框中输入一个新项时自动添加到组合框中,并给出相应提示;当输入一个已存在项时给出相应提示。(源代码+运行界面)
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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Items.Add("洛阳");
}
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (comboBox1.Items.Contains(comboBox1.Text))
{
label2.Text = "你的输入已在组合框!";
}
else
{
comboBox1.Items.Add(comboBox1.Text);
label2.Text = "你的输入项已添加到组合框中!";
}
}
}
}
3.创建Windows窗体应用程序,用一个学生结构数组存放10名学生的记录,然后根据用户指定的学号显示相应的学生记录,具体界面如下所示。(源代码+运行界面)
Textbox空间显示内容为灰在属性里讲enable设置为false即可
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 _4_3
{
public partial class Form1 : Form
{
public struct student
{
public int stunum;
public string name;
public string sex;
public int classnum;
public string birthday;
}
student[] stu = new student[]{
new student(){stunum = 1,name = "钢铁侠", sex = "男",classnum = 101, birthday = "2008/4/30"},
new student(){stunum = 2,name = "黑寡妇", sex = "女",classnum = 102, birthday = "2010/5/07"},
new student(){stunum = 3,name = "雷神", sex = "男", classnum = 103, birthday = "2011/5/06"},
new student(){stunum = 4,name = "绿巨人", sex = "男", classnum = 104, birthday = "2008/6/13"},
new student(){stunum = 5,name = "美国队长", sex = "男", classnum = 105, birthday = "2011/9/9"},
new student(){stunum = 6,name = "鹰眼", sex = "男", classnum = 106, birthday = "2012/5/5"},
new student(){stunum = 7,name = "战争机器", sex = "男", classnum = 107, birthday = "2010/5/07"},
new student(){stunum = 8,name = "洛基", sex = "男", classnum = 108, birthday = "2011/5/06"},
new student(){stunum = 9,name = "幻视", sex = "可能是男", classnum = 109, birthday = "2015/5/01"},
new student(){stunum = 10,name = "绯红女巫", sex = "女", classnum = 110, birthday = "2015/5/01"},
};
public Form1()
{
InitializeComponent();
for (int i = 1; i <= 10; i++)
{
comboBox1.Items.Add(i.ToString());
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = stu[int.Parse(comboBox1.Text)-1].stunum.ToString();
textBox2.Text = stu[int.Parse(comboBox1.Text)-1].name;
textBox3.Text = stu[int.Parse(comboBox1.Text)-1].sex;
textBox4.Text = stu[int.Parse(comboBox1.Text)-1].classnum.ToString();
textBox5.Text = stu[int.Parse(comboBox1.Text)-1].birthday;
}
}
}
4.创建一个项目,设计一个窗体Form1,其中包含一个TreeView控件treeView1和一个ListView控件listView1,单击treeView1控件中的某结点时,在listView1中显示所有子结点,并通过弹出式菜单选择listView1控件的大图标、小图标、列表和完整图标4种视图显示模式。如下图所示:(源代码+运行界面)
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 _4_4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
treeView1.Nodes.Add("哺乳动物");
treeView1.Nodes.Add("鱼类");
treeView1.Nodes.Add("鸟类");
treeView1.Nodes[0].Nodes.Add("人");
treeView1.Nodes[0].Nodes.Add("狗");
treeView1.Nodes[0].Nodes.Add("猫");
treeView1.Nodes[1].Nodes.Add("鲨鱼");
treeView1.Nodes[1].Nodes.Add("热带鱼");
treeView1.Nodes[1].Nodes.Add("金鱼");
treeView1.Nodes[2].Nodes.Add("麻雀");
treeView1.Nodes[2].Nodes.Add("燕子");
treeView1.Nodes[2].Nodes.Add("喜鹊");
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
listView1.LargeImageList = imageList1;
listView1.SmallImageList = imageList2;
listView1.View = View.LargeIcon;
string a = treeView1.SelectedNode.Text;
if (a == "哺乳动物")
{
listView1.Clear();
listView1.Items.Add("人",0);
listView1.Items.Add("狗",1);
listView1.Items.Add("猫",2);
}
else if (a == "鱼类")
{
listView1.Clear();
listView1.Items.Add("鲨鱼",3);
listView1.Items.Add("热带鱼",4);
listView1.Items.Add("金鱼",5);
}
else if (a == "鸟类")
{
listView1.Clear();
listView1.Items.Add("麻雀",6);
listView1.Items.Add("燕子",7);
listView1.Items.Add("喜鹊",8);
}
}
private void 大图标ToolStripMenuItem_Click(object sender, EventArgs e)
{
listView1.View = View.LargeIcon;
}
private void 小图标ToolStripMenuItem_Click(object sender, EventArgs e)
{
listView1.View = View.SmallIcon;
}
private void 列表ToolStripMenuItem_Click(object sender, EventArgs e)
{
listView1.View = View.List;
}
private void 完整图标ToolStripMenuItem_Click(object sender, EventArgs e)
{
listView1.View = View.Tile;
}
}
}
右键选择大图标:
右键选择小图标:
右键选择列表:
右键选择完整图标:
参考:https://blog.youkuaiyun.com/qq_41264055/article/details/106028557