手机版

Windows窗体程序的开发实验报告

时间:2025-07-09   来源:未知    
字号:

精通C#与.NET4.0数据库开发

实验报告

实验题目:

专 业 计算机科学与技术 学 生 姓 名 班 级 学 号 教 师 指 导 单 位 日 期

术教师

教师名签:年 月 日语

成 绩 评定备

注一

一、实验目的

1. 学会在Visual Studio 2010中创建和运行窗体程序。 2. 掌握Windows窗体的基本操作。 3. 学会使用常用的Windows控件。 4. 学会使用菜单和工具栏以及通用对话框。 二、实验环境

.NET框架开发环境 Visual Studio 2010 三、实验内容 例5-1、2:

源代码:

public partial class Form1 : Form {

public Form1( ) {

InitializeComponent( ); }

private void AddInputToLog(string input) {

this.tbLog.AppendText("\r\n" + input);

this.tbLog.ScrollToCaret( ); }

private void btnSubmit_Click(object sender, EventArgs e) {

string input = this.tbInput.Text; this.AddInputToLog(input); this.tbInput.Clear( ); }

}

例5-3、4:

源代码:

public partial class FrmMain : Form {

public FrmMain( ) {

InitializeComponent( );

}

private void btnSetProp_Click(object sender, EventArgs e) {

this.Text = "测试对话框";

this.FormBorderStyle = FormBorderStyle.FixedDialog; this.BackColor = Color.Gray; this.WindowState = FormWindowState.Normal;

this.MinimizeBox = false; this.Height = 200; this.Width = 400; this.TopMost = true; }

private FrmMain _CurrFrm = null;

private void btnCreate_Click(object sender, EventArgs e) {

if(this._CurrFrm == null) {

this._CurrFrm = new FrmMain( ); this._CurrFrm.Show( ); } else {

this._CurrFrm.Activate( ); } }

private void btnClose_Click(object sender, EventArgs e) {

if (this._CurrFrm != null) {

this._CurrFrm.Close( ); this._CurrFrm = null; } }

private void FrmMain_Load(object sender, EventArgs e) { }

}

例5-5:

源代码:

// label1参数设置

http://bel1.AutoSize = true;

http://bel1.BackColor = System.Drawing.Color.Red;

http://bel1.Font = new System.Drawing.Font("楷体_GB2312",

12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

http://bel1.ForeColor = System.Drawing.Color.White; http://bel1.Location = new System.Drawing.Point(68, 43); http:// = "label1";

http://bel1.Size = new System.Drawing.Size(232, 16); http://bel1.TabIndex = 0;

http://bel1.Text = "红底白字,楷体 小四号, 无边框";

http://bel1.Click += new System.EventHandler(http://bel1_Click); // label2参数设置

http://bel2.AutoSize = true;

http://bel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; http://bel2.Font = new System.Drawing.Font("幼圆", 15F,

System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

http://bel2.Location = new System.Drawing.Point(49, 79); http:// = "label2";

http://bel2.Size = new System.Drawing.Size(289, 22);

http://bel2.TabIndex = 1;

http://bel2.Text = "幼圆 小三 粗体, Single 边框";

http://bel2.Click += new System.EventHandler(http://bel2_Click);

例5-6:

源代码:

public partial class Form1 : Form {

private int _Value = 0; //btnShowMsg的Click事件处理函数

private void btnShowMsg_Click(object sender, EventArgs e) {

MessageBox.Show(string.Format("现在需要: {0} ", this._Value)); }

//“多一点”按钮Click事件处理函数

private void btnAdd_Click(object sender, EventArgs e) {

this._Value++;

this.lbRes.Text = string.Format("现在需要: {0} ", this._Value); }

//“少一点”按钮Click事件处理函数

private void btnSub_Click(object sender, EventArgs e) {

this._Value--;

this.lbRes.Text = string.Format("现在需要: {0} ", this._Value); } }

例5-7:

源代码:

public partial class Form1 : Form {

public Form1( ) {

InitializeComponent( ); }

private void buttons_CheckedChanged(object sender, EventArgs e) {

string weeks = "";

weeks += ckbWeek1.Checked ? "星期一 " : ""; weeks += ckbWeek2.Checked ? "星期二 " : ""; weeks += ckbWeek3.Checked ? "星期三 " : ""; weeks += ckbWeek4.Checked ? "星期四" : ""; weeks += ckbWeek5.Checked ? "星期五" : ""; weeks += ckbWeek6.Checked ? "星期六" : ""; weeks += ckbWeek7.Checked ? "星期日" : ""; string sport = "";

sport += rbSword.Checked ? "击剑" : ""; sport += …… 此处隐藏:5279字,全部文档内容请下载后查看。喜欢就下载吧 ……

Windows窗体程序的开发实验报告.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
    ×
    二维码
    × 游客快捷下载通道(下载后可以自由复制和排版)
    VIP包月下载
    特价:29 元/月 原价:99元
    低至 0.3 元/份 每月下载150
    全站内容免费自由复制
    VIP包月下载
    特价:29 元/月 原价:99元
    低至 0.3 元/份 每月下载150
    全站内容免费自由复制
    注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
    × 常见问题(客服时间:周一到周五 9:30-18:00)