C#—实验10.4
2016-06-05 11:00
399 查看
设计系统的登录窗体和主窗体:登录窗体(frmLogin)、一个MDI主窗体(frmMain)、两个子窗体(frm子窗体1、frm子窗体2)。要求:
在登录窗体中输入用户名和密码,正确后,才可进入MDI主窗体;通过菜单命令关闭主窗体。
具体要求:
(1)做法:先创建四个窗体,按上面要求修改各自的名称;
(2)登录窗体:大小不可调;显示时位于屏幕中央;没有最大化,最小化,关闭按钮。在登录窗体中,假设用户输入账号为“zhangsan",且密码为"123"(密码显示为*),
则通过登录,销毁登录窗体,同时打开主窗体。否则给出错误提示,如:“账号或密码错误”。
Form1:using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox2.Text == "123")
this.DialogResult = DialogResult.OK;
else
{
DialogResult dr = MessageBox.Show("密码错误", "密码验证", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question);
if (dr == DialogResult.Retry)
{
textBox2.Text = "";
textBox2.Focus();
}
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
Form2:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void 关闭窗体ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
Program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
frmLogin loginFrm = new frmLogin();
loginFrm.ShowDialog();
if (loginFrm.DialogResult == DialogResult.OK)
Application.Run(new frmMain());//指定启动窗体
}
}
}
修改基本属性:
将登录窗体的StartPosition设置为“CenterScreen”;
将登录窗体的FormBorderStyle设置为“None";
运行结果:
密码输入正确后,进入主窗体:
相关文章推荐
- c#调用COM组件
- C#实现把指定数据写入串口
- C#动态创建button的方法
- C#中抽象方法与虚拟方法的区别
- c#中虚函数的相关使用方法
- C#实现给图片加水印的方法
- C#使用加边法计算行列式的值
- C#实现多线程的同步方法实例分析
- C#中尾递归的使用、优化及编译器优化
- C#中的delegate委托类型基本学习教程
- C#实现子窗体与父窗体通信方法实例总结
- C#通用邮件发送类分享
- 举例讲解C#中自动实现的属性
- C#中this的用法集锦
- C#数据结构之顺序表(SeqList)实例详解
- C#.NET获取拨号连接的宽带连接方法
- C#异步绑定数据实现方法
- C#实现AddRange为数组添加多个元素的方法
- C#中Equality和Identity浅析
- C#比较二个数组并找出相同或不同元素的方法