实验六 windows编程
贺州学院
C#程序设计与开发实战实验报告
班级: 实验名称: 一、实验目的
1.掌握窗体的常用属性和方法的使用。
2. 掌握文本操作类控件中的标签控件和文本控件的使用。
3.掌握选择操作类控件中的复选框、单选框、列表框、组合框的使用。 二、实验内容
1. 试编写Windows应用程序,完成下列要求:
(1)Form1(登陆窗口)和Form2窗体设计界面如下:注意Form1窗口的外形设置。
14软件2 姓名: 学号 完成时间 2016/5/31 实验六 Windows编程
(2)应用程序从Form1启动,输入用户名和密码,要求:密码框以字符“#”代替用户输入显示;
(3)当用户单击Form1中的“登陆”按钮时,弹出Form2窗体,并将用户输入的用户名和密码传递到Form2的只读textBox中显示;
(4)当用户单击Form2中的“返回”按钮时,关闭Form2窗体,并将Form1窗体中的两个textBox清空;
(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 Test1 {
public partial class Form1 : Form
{
public Form1() {
this.StartPosition = FormStartPosition.CenterScreen; //窗口居中显示 InitializeComponent(); }
//登录按钮
private void button1_Click(object sender, EventArgs e) {
if (textBox1.Text == \ {
MessageBox.Show(\请输入用户名!\提示信息\
return; }
if (textBox2.Text == \ {
MessageBox.Show(\请输入密码!\\提示信息\MessageBoxButtons.OK, MessageBoxIcon.Warning);
return; }
Form2 f2 = new Form2(); //定义from2窗口的对象 f2.user = textBox1.Text; //记住当前用户名 f2.pass = textBox2.Text; //记住当前密码 f2.Parent = this;
this.Hide(); //隐藏父窗口
f2.Show(); //显示子窗口 }
//取消按钮
private void button2_Click(object sender, EventArgs e) {
if (DialogResult.Yes == MessageBox.Show(\是否退出?\\提示信息\MessageBoxButtons.YesNo))
{ this.Close(); } }
//窗口活动时执行的代码
private void Form1_Activated(object sender, EventArgs e) {
textBox1.Text = \ textBox2.Text = \ textBox1.Focus();
}
private void Form1_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 Test1 {
public partial class Form2 : Form {
public Form1 Parent; //父窗口 public String user, pass; //用户名、密码 public Form2() {
this.StartPosition = FormStartPosition.CenterScreen; //窗口居中显示 InitializeComponent(); }
//返回按钮
private void button1_Click(object sender, EventArgs e) {
if (DialogResult.Yes == MessageBox.Show(\是否返回?\\提示信息\MessageBoxButtons.YesNo))
{
this.Parent.Show(); //显示父窗口 this.Close(); //关闭子窗口 } }
//加载窗口
private void Form2_Load(object sender, EventArgs e) {
textBox1.Text = user; //显示用户名 textBox2.Text = pass; //显示密码
}
//关闭窗口
private void Form2_FormClosed(object sender, FormClosedEventArgs e) {
this.Parent.Show(); //显示父窗口 } } }
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 Windows1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent(); }
private void textBox2_TextChanged(object sender, EventArgs e) { }
private void textBox1_TextChanged(object sender, EventArgs e) { }
private void button1_Click(object sender, EventArgs e) {
Form2 frm2 = new Form2(); //实例化Form2 frm2.user = textBox1.Text; frm2.password = textBox2.Text; frm2.myparent = this; this.Hide();
if (textBox1.Text == \ frm2.Show(); //调用Show方法显示Form2窗体 else {
MessageBox.Show(\密码或者用户名不正确,请重新输入\ textBox1.Text = \ textBox2.Text = \ textBox1.Focus(); } }
private void Form1_Load(object sender, EventArgs e) {
textBox2.MaxLength = 6;
textBox2.PasswordChar = '#'; }
private void button2_Click(object sender, EventArgs e) {
textBox1.Text = \ textBox2.Text = \ textBox1.Focus(); }
private void Form1_Activated(object sender, EventArgs e) {
textBox1.Text = \ textBox2.Text = \ } } }
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 Windows1 {
public partial class Fo …… 此处隐藏:1986字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [互联网资料]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 《近代科学之父牛顿》 课
- 高中生物《第四章 第二节 探讨加酶洗衣




