教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 互联网资料 >

实验六 windows编程(2)

来源:网络收集 时间:2026-08-24
导读: { 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, FormC

{

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字,全部文档内容请下载后查看。喜欢就下载吧 ……

实验六 windows编程(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/443947.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)