实验六 windows编程(2)
{
textBox1.Text = user; textBox2.Text = password; }
private void button1_Click(object sender, EventArgs e) {
this .Close(); this .myparent.Show(); }
private void Form2_FormClosed(object sender, FormClosedEventArgs e) {
this.myparent.Show(); } } }
2. 试编写Windows应用程序,完成下列要求:
(1)Form2(登陆窗口)和Form1(我的应用程序)窗体设计界面如下。注意Form2窗口的外形设置,另外主方法中的Application.Run(new Form1());不能修改。
(2)运行应用程序时弹出登录窗口,输入用户名和密码,要求:密码框以字符“*”代替用户输入显示(注意登录窗体要求显示在屏幕中间);
(3)当用户单击Form2中的“登陆”按钮时,如果用户名和密码都正确,就关闭登录窗口并弹出Form1窗体,并将用户输入的用户名和密码传递到Form1的richTextBox1分行显示;如果密码不正确,则弹出消息框显示错误信息,并提示重新输入;
(4)当用户单击“取消”按钮时,结束整个程序的运行; (5)当用户关闭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 Test2 {
public partial class Form2 : Form {
public Form2() {
this.StartPosition = FormStartPosition.CenterScreen; //窗口居中显示 InitializeComponent(); }
//登录按钮
private void button1_Click(object sender, EventArgs e) {
if (textBox1.Text == \ {
MessageBox.Show(\请输入用户名!\\提示信息\MessageBoxButtons.OK, MessageBoxIcon.Warning);
return; }
if (textBox2.Text == \ { MessageBox.Show(\请输入密码!\\提示信息\MessageBoxButtons.OK, MessageBoxIcon.Warning);
return; }
//判断用户名和密码是否正确
if (textBox1.Text == \ {
Form1.user = textBox1.Text; Form1.pass = textBox2.Text;
this.Close(); //关闭登录窗口 } else {
MessageBox.Show(\用户名或密码输入不正确,请重新输入!\\提示信息\MessageBoxButtons.OK, MessageBoxIcon.Warning);
textBox1.Text = \ textBox2.Text = \ textBox1.Focus(); }
}
private void button2_Click(object sender, EventArgs e) {
if (DialogResult.Yes == MessageBox.Show(\是否退出?\\提示信息\MessageBoxButtons.YesNo))
{
Application.Exit(); //退出整个应用程序
} }
private void Form2_Load(object sender, EventArgs e) {
} } }
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 Test2 {
public partial class Form1 : Form {
public static string user, pass; //显示用户名、密码 public Form1() {
this.StartPosition = FormStartPosition.CenterScreen; //窗口居中显示 InitializeComponent(); }
//加载窗口
private void Form1_Load(object sender, EventArgs e) {
richTextBox1.AppendText(Form1.user+\ //显示用户名和密码
} } }
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 Windows2 {
public partial class Form2 : Form {
public Form2() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
Form1 frm1 = new Form1(); //实例化Form1 Form2 frm2 = new Form2(); //实例化Form2 frm1.test1 = textBox1.Text; frm1.test2 = textBox2.Text; frm1.myparent = this; this.Hide();
if (textBox1.Text == \this.Close(); else {
MessageBox.Show(\密码或者用户名不正确,请重新输入\ textBox1.Text = \ textBox2.Text = \
frm2.Show(); //调用Show方法显示Form2窗体 textBox1.Focus(); this.Close(); } }
private void Form2_Load(object sender, EventArgs e) {
textBox1.MaxLength = 6;
textBox2.PasswordChar = '*'; }
private void button2_Click(object sender, EventArgs e) { this.Close();
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e) { this.Close();
} } }
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 Windows2 {
public partial class Form1 : Form {
public string test1,test2; public Form myparent; public Form1() {
InitializeComponent(); }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) {
//this.Close();
//this.myparent.Show(); }
private void Form1_Load(object sender, EventArgs e) {
richTextBox1.Text = test1; richTextBox1.Text = …… 此处隐藏:1974字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [互联网资料]2022年厦门大学机电工程系824机械设计
- [互联网资料]东南大学2022年硕士研究生拟录取名单公
- [互联网资料]能源调研报告(精选多篇)
- [互联网资料]初三英语下学期 中考英语 语法填空训练
- [互联网资料]2022内蒙古选调生行测常识备考:新事物
- [互联网资料]自驾必备!在新西兰租什么样的车自驾游
- [互联网资料]佛教素食菜谱44页未完
- [互联网资料]盈利能力分析外文翻译
- [互联网资料]2022年南昌航空大学音乐学院736马克思
- [互联网资料]优选外贸跟单实习报告总结(精品版)
- [互联网资料]银行新员工培训总结
- [互联网资料]2_year_visa_new_guidance_190316
- [互联网资料]天津市五校宝坻一中静海一中杨村一中芦
- [互联网资料]2007--2008学年第一学期高三数学宁波市
- [互联网资料]Chromatic framework for vision in ba
- [互联网资料]幼儿园大班上学期美术教案《心愿树》含
- [互联网资料]2022年华中农业大学信息学院820微型计
- [互联网资料]硬盘坏道的表现 __硬盘使用久了
- [互联网资料]江苏省2016年会计从业资格考试《会计基
- [互联网资料]公共场所卫生监督试卷全解
- 高级英语第一册所有修辞方法及例子总结
- 综合交通枢纽规划与城市发展
- 沃尔玛的企业文化案例分析
- 美国Thanksgiving Day 感恩节 介绍
- PEP六年级英语上册Unit6How do you fee
- 最齐全的中国大型商场购物中心名单
- 数据结构实验报告八—哈夫曼编译码
- 杭州市余杭区人民政府(通知)
- 七年级语文成语运用专项训练
- 微观经济学第三章 消费者行为 课后习题
- 对_钱学森之问_的思考
- Excel_三级联动_下拉菜单
- 办公用品需求计划申请表
- 对外汉语教材必须要知道的发展史
- 挑战杯大学生学术科技作品竞赛作品申报
- 举办民办教育培训机构应具备下列条件
- 太阳能路灯项目设计方案
- 2013年八年级上最新人教版新教材Unit3I
- 【历史】 6-4 《近代科学之父牛顿》 课
- 高中生物《第四章 第二节 探讨加酶洗衣




