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

 /// <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进行设置即可(此属性是点击父窗体进行设置)。

C# WinForm窗体应用(第四天)的更多相关文章

  1. WinForm 窗体属性 窗体美化

    WinForm是·Net开发平台中对Windows Form的一种称谓. Windows窗体的一些重要特点如下: 功能强大:Windows窗体可用于设计窗体和可视控件,以创建丰富的基于Windows的 ...

  2. WinForm窗体嵌入

    一.在winform窗体上添加两个控件 1.容器>Panel 2.添加 SideBar.dll (下载链接:http://pan.baidu.com/s/1o6qhf9w) (1)将SideBa ...

  3. Winform窗体实现简单的二维码生成和保存

    二维码的生成需要用到二维码生成的类库,ThoughtWorks.QRCode.dll 步骤: 第一步:下载二维码生成类库,ThoughtWorks.QRCode.dll 第二步:新建winform项目 ...

  4. C#:绘制Winform窗体

    Winform窗体缺少左上角效果: public void SetWindowRegion() { System.Drawing.Drawing2D.GraphicsPath FormPath; Fo ...

  5. C#.NET vs2010中使用IrisSkin4.dll轻松实现WinForm窗体换肤功能

    IrisSkin2.dll是一款很不错的免费皮肤控件,利用它可以轻松的实现WinForm窗体换肤 然而IrisSkin2.dll只能在.NET Faremwork 4.0以及之前的版本使用,所以要在V ...

  6. winform窗体嵌套HTML页面,开发出炫彩桌面程序

    一:CEF全称Chromium Embedded Framework,是一个基于Google Chromium 的开源项目.Google Chromium项目主要是为Google Chrome应用开发 ...

  7. C# winform 窗体应用程序之图片上传Oracle数据库保存字段BLOB

    C# winform 窗体应用程序之图片上传Oracle数据库保存字段BLOB 我用的数据库是Oracle,就目前来看,许多数据库现在都倾向于Oracle数据库,对ORACLE数据库基本的操作也是必须 ...

  8. xBIM 实战04 在WinForm窗体中实现IFC模型的加载与浏览

    系列目录    [已更新最新开发文章,点击查看详细]  WPF底层使用 DirectX 进行图形渲染.DirectX  能理解可由显卡直接渲染的高层元素,如纹理和渐变,所以 DirectX 效率更高. ...

  9. winform 窗体圆角设计

    网上看到的很多winform窗体圆角设计代码都比较累赘,这里分享一个少量代码就可以实现的圆角.主要运用了System.Drawing.Drawing2D. 效果图 代码如下. private void ...

  10. winform窗体置顶

    winform窗体置顶 金刚 winform 置顶 今天做了一个winform小工具.需要设置置顶功能. 网上找了下,发现百度真的很垃圾... 还是必应靠谱些. 找到一个可以链接. https://s ...

随机推荐

  1. [bzoj4033][HAOI2015]树上染色_树形dp

    树上染色 bzoj-4033 HAOI-2015 题目大意:给定一棵n个点的树,让你在其中选出k个作为黑点,其余的是白点,收益为任意两个同色点之间距离的和.求最大收益. 注释:$1\le n\le 2 ...

  2. poj——2084  Game of Connections

    Game of Connections Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8664   Accepted: 42 ...

  3. - > 听学姐讲那过去的故事——打代码的小女孩

    童话故事 不知道大家有没有看过  天冷极了,下着雪,又快黑了.这是一年的最后一天——大年夜.在这又冷又黑的晚上,一个乖巧的小女孩在机房里调试程序.她从家里出来的时候还穿着一件外套,但是有什么用呢?那是 ...

  4. jquery-mobile 学习笔记之二(表单创建)

    绪上 一.注意事项 1. <form> 元素必须设置 method 和 action 属性 2. 每一个表单元素必须设置唯一的 "id" 属性. 该 id 在网站的页面 ...

  5. HTTP 错误 404.15 - Not Found 请求筛选模块被配置为拒绝包含的查询字符串过长的请求。

    HTTP 错误 404.15 - Not Found 请求筛选模块被配置为拒绝包含的查询字符串过长的请求. 2018-04-20 14:00 by 码农小周, 21 阅读, 2 评论, 收藏, 编辑 ...

  6. openGl学习之基本图元

    从本篇開始,会给出一些代码实例,所以要配置好编译环境. 环境配置: vs2012下配置链接http://www.cnblogs.com/dreampursuer/archive/2014/05/27/ ...

  7. LeetCode 69. Sqrt(x) (平方根)

    Implement int sqrt(int x). Compute and return the square root of x. x is guaranteed to be a non-nega ...

  8. 技术的止境(客户价值第一,快速实现第二,边做边学,迅速成为牛人。紧贴客户的需求去做技术,立于不败之地。追求的目标:把一项产品去做好,用产品去养活自己和家人)good

    作为一个依靠技术来谋生的程序员,我最近一直在思考一个问题,有限的生命里,面对无限的技术更新,我要研究到什么程度才能算是完成我的成为技术大牛的目标呢?换而言之,那就是技术的止境在哪儿呢?深入的思考下去, ...

  9. cocos2d-x 3.0 常见问题及解决

    我自己遇到的问题记录,会及时更新.希望对大家有帮助 1.打包图片生成plist后,假设在游戏中图片挨在一起可能会出现黑线,打包时将Extrude设为1就可以 2.Xcode环境下.更新资源后执行的时候 ...

  10. regEx in Groovy

    // 使用正则 得到非纯XML文件中的信息 // Response 经常得到的不是纯XML def pattern = ~/(<NewDataSet>).*(<\/NewDataSe ...