一、点击登录按钮,将两个窗体进行连接,并进行用户名和密码验证。

 /// <summary>
/// 登录设置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnLogin_Click(object sender, EventArgs e)
{
string userName = this.textBox1.Text;
string pwd = this.textBox2.Text;
if(userName=="haha"){
if(pwd==""){
MessageBox.Show("登陆成功!");
//链接两个页面
WFromMain mainWindow = new WFromMain();
mainWindow.Show();//展示WFromMain此窗体
this.Hide();//隐藏Form1窗体
}
else
{
MessageBox.Show("输入密码有误,请重新输入!");
this.textBox2.Text = "";
}
}
else
{
MessageBox.Show("用户不存在!");
this.textBox1.Text = "";
this.textBox2.Text = "";
}
}

二、在同一个解决方案中调用不同窗体的方法

在如下位置进行修改,并且切换调用即可:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms; namespace WindowsFormLogin01
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

针对不同的窗体,要切换时对      Application.Run(new Form1());      这一行的  Form1   进行修改即可。

三、项目实现代码(暂存)

 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 WindowsFormsDemo1
{
public partial class FrmMain1 : Form
{
public FrmMain1()
{
InitializeComponent();
} private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("保存操作");
} private void EditToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("编辑操作");
} private void AddEmloyeeToolStripMenuItem_Click(object sender, EventArgs e)
{
// MessageBox.Show("添加员工操作");
FrmAddEmployee addEmployee = new FrmAddEmployee(); //判断 是否有子窗体
if (this.MdiChildren == null || this.MdiChildren.Length == ) {
addEmployee.Show();
addEmployee.MdiParent = this;//给子窗体 指定 主窗体
return;
} bool flag = false;
foreach (var item in this.MdiChildren)
{
if (item.Text == addEmployee.Text) {
addEmployee = item as FrmAddEmployee;
addEmployee.Activate();
flag = true;
break;
}
}
if (!flag) {
addEmployee.Show();
addEmployee.MdiParent = this;//给子窗体 指定 主窗体
}
} /// <summary>
/// 弹出修改窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ModifyEmployeeToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmModifyEmployee modifyEmployee = new FrmModifyEmployee(); if (this.MdiChildren == null || this.MdiChildren.Length == )
{
modifyEmployee.Show();
modifyEmployee.MdiParent = this;//给子窗体 指定 主窗体
return;
}
bool f = false;
foreach (var item in this.MdiChildren)
{
if (modifyEmployee.Text == item.Text) {
modifyEmployee = item as FrmModifyEmployee;
modifyEmployee.Activate();
f = true;
break;
}
} if (!f) {
modifyEmployee.Show();
modifyEmployee.MdiParent = this;
} } private void FrmMain1_FormClosing(object sender, FormClosingEventArgs e)
{
Environment.Exit();//关闭整个运行环境 } private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
{ int len = this.MdiChildren.Length;
for (int i = ; i <len ; i++)
{
Form frm = this.MdiChildren[];
frm.Close();
}
}
}
}

四、限制子窗体不超出父窗体界限

 private void SchoolToolStripMenuItem_Click(object sender, EventArgs e)
{
//点击后显示SchoolTan这个弹窗
SchoolTan schooltanchuang=new SchoolTan();
schooltanchuang.Show();
//让子窗体不超出父窗体界限
this.IsMdiContainer = true;
WFromMain mainForm = new WFromMain();
schooltanchuang.MdiParent = this;
/*
* 方法:明确父子关系:
son form = new Form();
form.MdiParent = this(father);
form.show();
前提是先要设置father窗体
isMdiContainer = true;
* **/
}

五、鼠标点击右键弹出菜单,并全部关闭弹出所有窗口。

 private void 关闭全部窗体ToolStripMenuItem_Click(object sender, EventArgs e)
{
Environment.Exit();
}

并将右边属性菜单的contextMenuStrip进行设置即可(此属性是点击父窗体进行设置)。

最新文章

  1. Docker 简介
  2. python判断类型
  3. Linux / Unix Command: bunzip2--reference
  4. 169 Majority Element [LeetCode Java实现]
  5. Cocos开发中性能优化工具介绍之使用Windows任务管理器
  6. Json 处理datetime
  7. java 使用正则表达式对文件名非法字符处理
  8. java并发编程_基本模块构建
  9. FormsAuthentication登录ReturnUrl使用绝对路径
  10. Activiti第三篇【连接、排他网关、指定任务处理人、组任务】
  11. PHP获取一周的日期
  12. React Native随笔——警告处理方法(持续更新)
  13. vue项目总结
  14. AE视频制作 参考 资源 科幻科技风格 开场 公司企业宣传
  15. 【转】导致SQL执行慢的原因
  16. VirtualBox fedora29 安装
  17. 【Spark调优】:如果实在要shuffle,使用map侧预聚合的算子
  18. Git使用—第一讲:初识版本控制工具
  19. saltstack二次开发(二)
  20. centos7配置网桥

热门文章

  1. 如何取消codeblocks对msvcr100.dll的依赖?
  2. E - Super Jumping! Jumping! Jumping! DP
  3. CI session 类的用法
  4. Python3基础(五) 函数
  5. sqlite 数据库 相关知识
  6. 数据挖掘算法学习(八)Adaboost算法
  7. Chrome控制台命令
  8. P1656 炸铁路
  9. mac关闭和开启启动声
  10. P1491 集合位置 次短路