多重窗体实验
来源:互联网 发布:node js前景 知乎 编辑:程序博客网 时间:2024/06/18 12:39
题目要求:
设计系统的的登录窗体和主窗体:登录窗体(frmLogin),一个MDI主窗体(frmMain),两个子窗体(frm子窗体1,frm子窗体2)。要求在登录窗体中输入用户名和密码,用户名和密码正确后,才可进入MDI主窗体;通过菜单命令关闭主窗体。具体要求:。。。。
输入代码:
using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace login3_1{ static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form1 f = new Form1(); if (f.ShowDialog()==DialogResult.OK) { Application.Run(new Form1()); } } }}
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace login3_1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void 打开子窗体1ToolStripMenuItem_Click(object sender, EventArgs e) { foreach (var item in this.MdiChildren) { item.Dispose(); } window21 w = new window21(); //w.MdiParent = this;//设置当前窗体为父窗体 w.Show(); } private void 打开子窗体2ToolStripMenuItem_Click(object sender, EventArgs e) { foreach (var item in this.MdiChildren) { item.Dispose(); } window22 w2 = new window22(); //w2.MdiParent = this; w2.Show(); } }}
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace login3_1{ public partial class window21 : Form { string str1="hg", str2="123"; public window21() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (textBox2.Text == str2 && textBox1.Text == str1) { this.DialogResult = DialogResult.OK; window23 w3 = new window23(); w3.Show(); } else { DialogResult dr = MessageBox.Show("密码错误", "密码验证", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question); if (dr == DialogResult) { Application.Exit(); textBox2.Text = ""; textBox2.Focus(); } textBox2.Text = ""; } } private void button2_Click(object sender, EventArgs e) { Application.Exit(); } }}
运行截图:
总结:
C#做应用上手的速度超乎自己的想象。。。
0 0
- 多重窗体实验
- 窗体实验
- C#—多重窗体
- 窗体实验-猜数字
- C#——窗体实验
- 窗体实验之文本框实例
- c# 多重窗体间,在本窗体中设置或引用其它窗体的属性
- C#第九周实验之窗体设计
- c#——窗体实验-最初版
- 窗体实验之单选按钮
- 实验03:《代码复用--添加主窗体》实验指导书
- C#——窗体实验—进阶-文本框实验
- 第十二周实验报告2(多重继承)
- 第十二周实验报告(任务二)【多重继承】
- 哈工大 《.NET程序设计》 实验1:开发Windows窗体应用程序
- C#上机 第十周 任务1 我的窗体实验
- C#WindowForm窗体实验-----招评标管理系统
- C#—窗体的基本操作(实验8.1、8.2)
- censys 数据库地理信息自定义接口(python版)
- SQL之EXPLAIN语法
- Guava base -- Charset
- mysql:The package 'mysql' can be found in following packages
- 字符串 判空
- 多重窗体实验
- Mac之vim命令使用
- android.text.TextUtils中的常用方法
- XML(6)自己写一个xml序列化器
- Java 内部类
- ExpandableListView
- 【Java】——Eclipse打开路径错误
- php后台框架
- Unity3D架构系列之- FSM有限状态机设计一