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

 /// <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. css3的高级而有用且很少人知道的属性和样式

    1.-webkit-mask 概属性可以给一个元素添加蒙层,蒙层可以是一个渐变或者半透明的png图片,这张png图片的 alpha 为 0 的位置会不显示元素这部分,alpha 为 1 的位置会显示元 ...

  2. 创建NetCore2.2 Web项目+EFCore+SQLServer

    在空余时间学习下NetCore,记录日常,供参考. 1.确保已下载安装NetCore2.2SDK 环境,下载地址:https://dotnet.microsoft.com/download/dotne ...

  3. HDOJ 5402 Travelling Salesman Problem 模拟

    行数或列数为奇数就能够所有走完. 行数和列数都是偶数,能够选择空出一个(x+y)为奇数的点. 假设要空出一个(x+y)为偶数的点,则必须空出其它(x+y)为奇数的点 Travelling Salesm ...

  4. Android MTP 文件浏览Demo

    本apk实现了MTP文件浏览的简单功能. 通过Demo apk能够浏览连接到当前设备上的MTP设备上的文件. Demo路径:http://download.csdn.net/detail/sailin ...

  5. LeetCode 976. Largest Perimeter Triangle (三角形的最大周长)

    题目标签:Array 题目给了我们一个 边长的 array, 让我们找出 最大边长和的三角形,当然前提得是这三条边能组成三角形.如果array 里得边长组成不了三角形,返回0. 最直接的理解就是,找到 ...

  6. Linux对外连接port数限制

    左右时,開始大量抛例如以下异常: java.net.BindException:Cannot assign requested address atsun.nio.ch.Net.connect0(Na ...

  7. Android 使用MediaRecorder录音调用stop()方法的时候报错【转】

    本文转载自:http://blog.csdn.net/u014737138/article/details/49738827 这个问题在网上看到了太多的答案,一直提示说按照官网的api的顺序来,其实解 ...

  8. 【POJ 3349】 Snowflake Snow Snowflakes

    [题目链接] http://poj.org/problem?id=3349 [算法] 哈希 若两片雪花相同,则它们六个角上的和一定相同,不妨令 H(A) = sigma(Ai) % P ,每次只要到哈 ...

  9. 洛谷 P4149 [ IOI 2011 ] Race —— 点分治

    题目:https://www.luogu.org/problemnew/show/P4149 仍然是点分治: 不过因为是取 min ,所以不能用容斥,那么子树之间就必须分开算,记录桶时注意这个: 每次 ...

  10. E20170627-gg

    ring   n. 戒指,指环; 铃声,钟声; 环形物; 拳击场;   vi. 按铃,敲钟; 回响; 成环形; rear   n. 后部,背面,背后; 臀部; (舰队或军队的) 后方,后尾,殿后部队; ...