C# Winform编程(2)常用控件
- 常用控件
常用控件
标签,文本,按钮,列表框,组合框等的使用
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 学生成绩管理系统
{
internal static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormWelcome());
}
}
}
FormWelcome.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;
namespace 学生成绩管理系统
{
public partial class FormWelcome : Form
{
public FormWelcome()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
linkLabel1.LinkVisited = true;
FormLogin loginForm = new FormLogin();
loginForm.Show();
this.Hide();
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
labelWelcome.Visible = true;
// labelWelcome.Show();
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
labelWelcome.Visible = false;
// labelWelcome.Hide();
}
private void FormWelcome_Load(object sender, EventArgs e)
{
}
}
}
FormLogin.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;
namespace 学生成绩管理系统
{
public partial class FormLogin : Form
{
public FormLogin()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBoxUserName.Text == string.Empty || textBoxPassWord.Text == string.Empty)
{
MessageBox.Show("信息禁止为空!", "登录提示");
textBoxUserName.Clear();
textBoxPassWord.Clear();
textBoxPassWord.Focus();
return;
}
if (!textBoxUserName.Text.Equals("admin") || !textBoxPassWord.Text.Equals("admin"))
{
MessageBox.Show("用户名或密码错误!", "登录提示");
textBoxUserName.Clear();
textBoxPassWord.Clear();
textBoxPassWord.Focus();
return;
}
else {
MessageBox.Show("欢迎您登录本系统!", "消息提示");
FormMenu formMenu = new FormMenu();
formMenu.Show(this);
textBoxUserName.Clear();
textBoxPassWord.Clear();
textBoxPassWord.Focus();
//groupBox1.Hide();
this.Hide();
}
}
private void button2_Click(object sender, EventArgs e)
{
textBoxUserName.Clear();
textBoxPassWord.Clear();
textBoxPassWord.Focus();
}
private void FormLogin_Load(object sender, EventArgs e)
{
}
}
}
FormMenu.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;
namespace 学生成绩管理系统
{
public partial class FormMenu : Form
{
public FormMenu()
{
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("您选择的部门是:" + listBox1.SelectedItem.ToString() +
",位列第" + listBox1.SelectedIndex.ToString(), "提示信息");
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("已选择:" + comboBox1.SelectedItem.ToString() + ", 位列:"
+ comboBox1.SelectedIndex.ToString(), "提示信息");
}
private void FormMenu_Load(object sender, EventArgs e)
{
this.listBox1.Items.Add("软件部");
this.listBox1.Items.Add("硬件部");
this.listBox1.Items.Add("财务部");
this.listBox1.Items.Add("人事部");
this.comboBox1.Items.Add("产品部");
this.comboBox1.Items.Add("销售部");
this.comboBox1.Items.Add("生产部");
//this.comboBox1.SelectedIndex = 0;
}
}
}
程序运行效果: