C# WinForm窗体应用(第四天)
一、点击登录按钮,将两个窗体进行连接,并进行用户名和密码验证。
/// <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窗体应用(第四天)的更多相关文章
- WinForm 窗体属性 窗体美化
WinForm是·Net开发平台中对Windows Form的一种称谓. Windows窗体的一些重要特点如下: 功能强大:Windows窗体可用于设计窗体和可视控件,以创建丰富的基于Windows的 ...
- WinForm窗体嵌入
一.在winform窗体上添加两个控件 1.容器>Panel 2.添加 SideBar.dll (下载链接:http://pan.baidu.com/s/1o6qhf9w) (1)将SideBa ...
- Winform窗体实现简单的二维码生成和保存
二维码的生成需要用到二维码生成的类库,ThoughtWorks.QRCode.dll 步骤: 第一步:下载二维码生成类库,ThoughtWorks.QRCode.dll 第二步:新建winform项目 ...
- C#:绘制Winform窗体
Winform窗体缺少左上角效果: public void SetWindowRegion() { System.Drawing.Drawing2D.GraphicsPath FormPath; Fo ...
- C#.NET vs2010中使用IrisSkin4.dll轻松实现WinForm窗体换肤功能
IrisSkin2.dll是一款很不错的免费皮肤控件,利用它可以轻松的实现WinForm窗体换肤 然而IrisSkin2.dll只能在.NET Faremwork 4.0以及之前的版本使用,所以要在V ...
- winform窗体嵌套HTML页面,开发出炫彩桌面程序
一:CEF全称Chromium Embedded Framework,是一个基于Google Chromium 的开源项目.Google Chromium项目主要是为Google Chrome应用开发 ...
- C# winform 窗体应用程序之图片上传Oracle数据库保存字段BLOB
C# winform 窗体应用程序之图片上传Oracle数据库保存字段BLOB 我用的数据库是Oracle,就目前来看,许多数据库现在都倾向于Oracle数据库,对ORACLE数据库基本的操作也是必须 ...
- xBIM 实战04 在WinForm窗体中实现IFC模型的加载与浏览
系列目录 [已更新最新开发文章,点击查看详细] WPF底层使用 DirectX 进行图形渲染.DirectX 能理解可由显卡直接渲染的高层元素,如纹理和渐变,所以 DirectX 效率更高. ...
- winform 窗体圆角设计
网上看到的很多winform窗体圆角设计代码都比较累赘,这里分享一个少量代码就可以实现的圆角.主要运用了System.Drawing.Drawing2D. 效果图 代码如下. private void ...
- winform窗体置顶
winform窗体置顶 金刚 winform 置顶 今天做了一个winform小工具.需要设置置顶功能. 网上找了下,发现百度真的很垃圾... 还是必应靠谱些. 找到一个可以链接. https://s ...
随机推荐
- 解决win10磁盘占用过大的问题(亲测有效)
问题:打开任务管理器,经常会发现磁盘占用95%以上,电脑很卡,下面是解决方案 方法: 1.关闭家庭组. (1)搜索服务,找到“HomeGroupListener”服务,右键单击“属性”.在弹出属性界面 ...
- codevs3730 无线网络发射选址
题目描述 Description 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平行的129条东西向街道和129条南北向街道所形 ...
- java数组知识总结(一)//按类
在线api 目录: 零/数组(基本元素) 1. 声明一个数组 2. 创建一个数组 3. 数组名.length 4. 数组的引用 一/java.lang.reflect.Array / ...
- Fast Matrix Calculation 矩阵快速幂
One day, Alice and Bob felt bored again, Bob knows Alice is a girl who loves math and is just learni ...
- 【C语言】模拟实现strcmp函数
//模拟实现strcmp函数 //str1>str2,返回1 //str1=str2,返回0 //str1<str2,返回-1 #include <stdio.h> #incl ...
- 开源的轻量级JSON存储Kinto介绍
本文来源于我在InfoQ中文站翻译的文章,原文地址是:http://www.infoq.com/cn/news/2015/12/introducing-kinto Kinto是个提供了同步与分片功能的 ...
- JS执行环境栈及事件循环机制—简洁明了的讲解
JavaScript解释器在浏览器中是单线程的,这意味着浏览器在同一时间内只执行一个事件,对于其他的事件我们把它们排队在一个称为 执行栈(调用栈) 的地方.下表是一个单线程栈的抽象视图: 我们已经知道 ...
- 可编程数据平面将OpenFlow扩展至电信级应用(一)
可编程数据平面将OpenFlow扩展至电信级应用(一) 案例:基于WinPath网络处理器的电信极OpenFlow (CG-OF)client实现 作者:Liviu Pinchas, Tao Lang ...
- cocos2D(七)---- CCScene
CCScene普通情况是游戏里面的根节点.称之为"场景",执行游戏时须要通过CCDirector启动第一个场景. 当然,游戏略微复杂一点的话.可能会包括非常多个场景,这就涉及到场景 ...
- LeetCode 781. Rabbits in Forest (森林中的兔子)
题目标签:HashMap 题目给了我们一组数字,每一个数字代表着这只兔子说 有多少只一样颜色的兔子. 我们把每一个数字和它出现的次数都存入map.然后遍历map,来判断到底有多少个一样颜色的group ...