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 ...
随机推荐
- [SDOI2011]打地鼠
题目描述 打地鼠是这样的一个游戏:地面上有一些地鼠洞,地鼠们会不时从洞里探出头来很短时间后又缩回洞中.玩家的目标是在地鼠伸出头时,用锤子砸其头部,砸到的地鼠越多分数也就越高. 游戏中的锤子每次只能打一 ...
- codevs3410 别墅房间
题目描述 Description 小浣熊松松到他的朋友家别墅去玩,发现他朋友的家非常大,而且布局很奇怪.具体来说,朋友家的别墅可以被看做一个N*M的矩形,有墙壁的地方被标记为’#’,其他地方被标记为’ ...
- idea常用快捷键汇总
自动导入或补全 Ctrl+空格,代码提示自动提示待输入项 Ctrl+Shift+空格,自动补全代码语句 Ctrl+Alt+空格,类名自动完成 Ctrl+Shift + Enter,语句完成(完成当前语 ...
- Ubuntu 16.04安装汇编编译器NASM
NASM支持intel语法. 安装过程: 1.通过二进制包方式 下载: http://www.nasm.us/pub/nasm/releasebuilds/2.13/ 如果要下载其它版本可以把地址靠前 ...
- Oracle中的 row_number() over (partition by order by ) 用法
oracle 里面经常这样用 select col1,col2..., row_number() over (partition by colx order by coly) from table_n ...
- CHAPTER 1 Architectural Overview of Oracle Database 11g
Which SGA structures are required, and which are optional? The database buffer cache, log buffer, an ...
- Workflow:添加工作流存储功能
数据库准备: 1. 创建database(这里我们用的是MSSQL.Workflow支持其它数据库,但是MSSQL是配置最方便,不要问我为什么!). 2. 运行位于[%WINDIR%\Microsof ...
- 1.3-动态路由协议EIGRP
EIGRP(Enhanced IGRP) EIGRP的特点: IGRP/EIGRP都是CISCO的私有协议. 1:是唯一的一种LS/DV的混合协议. 2:Rapid convergence EIGRP ...
- Windows 9立即公布了
Windows 9技术预览版可能于今晚在美国旧金山举办的Windows公布会上宣布.下一代的Windows名称最有可能是Windows或Windows 9.网友猜想也可能是WIndows X或Wind ...
- starUML 2.5.1 for mac
http://www.macupdate.com/app/mac/55571/staruml/download 一直在windows下使用 star UML,占用资源少,简洁易用. Mac下也能够用了 ...